dont_be_hasty Posted March 23, 2009 Share Posted March 23, 2009 Hi Im creating a guestbook using the following tutorial: http://www.phpeasystep.com/workshopview.php?id=15 Ive basically just copied that code and only changed things like username, database name etc... However when the user enters their details, it does not seem to actually add the details to the database. A new entry is added to the table but the info taken from the html does not seem to get added to the database correctly. Here is the code from the pages. Page with form: <table width="400" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC"> <tr> <form id="form1" name="form1" method="post" action="addguestbook.php"> <td> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td width="117">Name</td> <td width="14">:</td> <td width="357"><input name="name" type="text" id="name" size="40" /></td> </tr> <tr> <td>Email</td> <td>:</td> <td><input name="email" type="text" id="email" size="40" /></td> </tr> <tr> <td valign="top">Comment</td> <td valign="top">:</td> <td><textarea name="comment" cols="40" rows="3" id="comment"></textarea></td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" value="Submit"><input type="reset" value="Reset"></td> </tr> </table> </td> </form> </tr> </table> Code to add info to database: <?php $username="root"; // Mysql username $password=""; // Mysql password $database="assocdb"; // Database name $tbl_name="guestbook"; // Table name // Connect to server and select database. mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die("Unable to select database"); $datetime=date("y-m-d h:i:s"); //date time $query="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')"; $result=mysql_query($query); //check if query successful if($result){ echo "<br>"; echo "<br>"; echo "Your comment was successfully added to the guestbook"; echo "<br>"; echo "<br>"; echo "<a href='viewguestbook.php'>View guestbook</a>"; // link to view guestbook page } else { echo "ERROR"; } mysql_close(); ?> </div> On this page the date/time is added correctly to the database, its just the info that is taken from the form that isnt added. There is a 3rd page that displays the info, but it shouldnt be that page that is causing the trouble. Thanks Quote Link to comment Share on other sites More sharing options...
gnawz Posted March 23, 2009 Share Posted March 23, 2009 the code is ok. We may need to dee the code that assigns the variables to $POST[]. 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.