PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Fri Sep 23, 2005 2:35 pm
I am making a site for a friend that has multi comment tables ok and well they all are going to use the same table as each other and will im making a filter for it now each one will have a hidden field called filter as you can see in this form..
Code: Select all
<form action="insert.php" METHOD="post">
<br><br><br><font color="B5B5B5">username:</font><br>
<input type="text" name="username" size="30" value=""><br>
<font color="B5B5B5">text to add:</font><br>
<input type="text" name="message" size="30" value=""><br>
<input name="filter" type="hidden" value="comment1">
<p><input type="submit" name="submit" value="Submit">
</form>
and here is the insert.php
Code: Select all
<?php
include 'db.php';
$username = $_POST['username'];
$message = $_POST['message'];
$filter = $_POST['filter'];
mysql_query("INSERT INTO gallery (username, message, filter, date) VALUES ('".$username."', '".$message."', '".$filter."', now())") or die(MySQL_Error());
header ("Location: icomment1.php");
?>
now i dont get a error but everything gets put in but the filter can someone help me out here please...
Thank you
Smackie
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Fri Sep 23, 2005 2:37 pm
what kind of datatype is "filter" set to recieve in your database?
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Fri Sep 23, 2005 2:39 pm
i have it as Varchar but i dont know if it should be something else in there
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Fri Sep 23, 2005 2:45 pm
and how many varchars can it accept? I know it seems stupid to ask but your code looks okay to me.....i could be missing something,it wouldn't be the first time;)
Last edited by
Charles256 on Fri Sep 23, 2005 2:48 pm, edited 2 times in total.
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Fri Sep 23, 2005 2:46 pm
well i set the limit at 25.. i must be missing something lol but i guess its because i have family over for the week and im just distracted lol
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Fri Sep 23, 2005 2:49 pm
hm.well if someone else comes up with a solution go with them.but a cheap workaround is to make a table called comment1 and set filter in that table to default to comment1.. :: shrugs :: also, i can't find a now() function BTW, where the devil is that? either way. sorry i couldn't be more help.
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Fri Sep 23, 2005 2:52 pm
now() function is for the date..
ryanlwh
Forum Commoner
Posts: 84 Joined: Wed Sep 14, 2005 1:29 pm
Post
by ryanlwh » Fri Sep 23, 2005 2:53 pm
Charles, NOW() is a mysql function. check the mysql manual.
Smackie, try echoing the filter out and see what's on screen. I don't see anything wrong with your code.
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Fri Sep 23, 2005 2:54 pm
i know what it's sposed to do but i couldn't find a now() function in the php manual. maybe i just can't type :: shrugs ::
ah ha. a mysql function!
i'll go read up on the later,thanks!
we've really gotta slow down our posting and editing children... hehe
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Fri Sep 23, 2005 2:57 pm
see on the table in database under filter it shows nothing going in there...
ryanlwh
Forum Commoner
Posts: 84 Joined: Wed Sep 14, 2005 1:29 pm
Post
by ryanlwh » Fri Sep 23, 2005 3:05 pm
that's why you should echo all the variables to see what's being output to the screen. you can also view source to see what's happening.
Did you put some quotes into the message? and btw, should message be in a textarea, not a text field?
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Fri Sep 23, 2005 3:19 pm
I got it working heres how i fixed it
Code: Select all
mysql_query("INSERT INTO gallery (username, message, filter, date) VALUES ('".$username."', '".$message."', '".$filter."', now())") or die(MySQL_Error());
all i had to do was
Code: Select all
mysql_query("INSERT INTO gallery (username, message, filter, date) VALUES ('$username', '$message', '$filter', now())") or die(MySQL_Error());
but thank you all for your help
Smackie
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Fri Sep 23, 2005 3:22 pm
in theory those should be the same thing...go SQL:-D
ryanlwh
Forum Commoner
Posts: 84 Joined: Wed Sep 14, 2005 1:29 pm
Post
by ryanlwh » Fri Sep 23, 2005 3:27 pm
Charles256 wrote: in theory those should be the same thing...go SQL:-D
Indeed. In PHP or Perl those two would produce the same string...
Probably just some random error unrelated to how the string was constructed... anyway, it's solved...