jd2007 Posted July 10, 2007 Share Posted July 10, 2007 $server=mysql_connect("localhost", "root") or die("Could not connect: " . mysql_error()); $connection=mysql_select_db("comment", $server); $queryc="INSERT INTO comments (name, comment) VALUES ($name, $comment)"; $resultc=mysql_query($query); $query2="SELECT comments.name, comments.comment FROM comments"; $result2=mysql_query($query2); while ($record = mysql_fetch_assoc($result2)) { while (list($fieldname, $fieldvalue) = each ($record)) { echo "<B>".$fieldvalue."</B><BR>"; echo "<BR>"; } } $name and $comment is taken by user input in a form outside this script Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 10, 2007 Share Posted July 10, 2007 "In a form outside this script" Do you mean that a different script makes the $name and $comment variables then you're calling the above script? If this is the case the two variables are lost. You'll need to carry them over with either the URL or by using sessions. Quote Link to comment Share on other sites More sharing options...
shamilton Posted July 10, 2007 Share Posted July 10, 2007 "Newbie, stay. Stay. Bad newbie. That's a very bad newbie." In your code - you need to make sure to not assume that variables are always defined somewhere else. Do something like this (depending on how you plan on sending the variables to this script): $name = (isset($_GET["name"])) ? $_GET["name"] : NULL; $comment = (isset($_GET["comment"])) ? $_GET["comment"] : NULL; $server=mysql_connect("localhost", "root") or die("Could not connect: " . mysql_error()); $connection=mysql_select_db("comment", $server); $queryc="INSERT INTO comments (name, comment) VALUES ($name, $comment)"; $resultc=mysql_query($query); $query2="SELECT comments.name, comments.comment FROM comments"; $result2=mysql_query($query2); while ($record = mysql_fetch_assoc($result2)) { while (list($fieldname, $fieldvalue) = each ($record)) { echo "<B>".$fieldvalue."</B><BR>"; echo "<BR>"; } } Change $_Get to whatever and change the variable names to whatever. 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.