bran Posted November 20, 2006 Share Posted November 20, 2006 Ok, I'm trying to make a very simple form to add comments to images in a gallery. I pretty much copied the form and the code to insert it into the db from a form I have that already works. For some reason, though, this one will not. It isn't giving errors or anything. I click submit, it reloads the page, and nothing is in the db. Can you spot any eerrors in the code? I know its going to be something dumb when I figure it out. Thanks for any help.[code]echo ('<form action="http://www.iwannabeaculjan.com/test/test2.php" method="post">');echo ('Submitted By:<input type="text" name="submitted" size="30"><br>');echo ('Comment:<textarea name="comment" rows=3 cols=30></textarea><br>');echo ('<input type="submit" value="Add Comment">');echo ('</form>');$submitted=$_POST['submitted'];$comment=$_POST['comment'];$time=time;if (isset($comment)) {$sql="INSERT INTO piccomments (picid, comment, when, who) VALUES ('$picid', '$comment', '$time', '$submitted')";$result=mysql_query($sql);}else { exit();[/code] Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted November 20, 2006 Share Posted November 20, 2006 [code]echo ('<form action="http://www.iwannabeaculjan.com/test/test2.php" method="post">');echo ('Submitted By:<input type="text" name="submitted" size="30"><br>');echo ('Comment:<textarea name="comment" rows=3 cols=30></textarea><br>');echo ('<input type="submit" value="Add Comment">');echo ('</form>');[/code]You don't need to enclose the arguments to echo in parens. This will work just fine:echo "hello, world";[code]$submitted=$_POST['submitted'];$comment=$_POST['comment'];[/code]You probably want to clean this data before submitting it:$submitted = "'" . addslashes($_POST['submitted']) . "'";$comment = "'" . addslashes($_POST['comment']) . "'";[code]$time=time;[/code]It might be optional, but I'd include the parens here:$time = "'" . addslashes(time()) . "'";[code]if (isset($comment)) {$sql="INSERT INTO piccomments (picid, comment, when, who) VALUES ('$picid', '$comment', '$time', '$submitted')";$result=mysql_query($sql);}else { exit();[/code]Where did you set $picid? Further, picid is probably an INT column, thus single parens are not necessary.I included the single parents for the other column values in the preceding lines, so you can drop them from the SQL statement.Where is the closing curly brace for your if statement? Quote Link to comment Share on other sites More sharing options...
bran Posted November 20, 2006 Author Share Posted November 20, 2006 $picid is set higher up in the file. it, along with the clsing brace for the if statement, got chopped off when I cut/pasted. The rest of the info sounds like good advice for neatening everything up, but if I understand all you're saying correctly, it all should work as it is (and it does on the other form, all I did was change the variables). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.