revsu Posted January 18, 2010 Share Posted January 18, 2010 Of the dozen or so php help sites, this seemed the most helpful. There was another post about this same issue, but it got confounded when the poster was confusing and then changed his question mid-stream. So, here goes :-) Yesterday, I found a very simple script set on phpeasystart.com. It works...sort of. I know nothing about php, but I understand algebra and html, so I figured out that guestbook.php posts to addguestbook.php which is supposed to insert the form field data into the mySQL table. The automatic ID number and the datetime stamp get added, but the name, email and comment fields are all blank. The viewguestbook.php dutifully displays the annoying blankness. I think the error must be in the addguestbook code, since the fields are blank in the table itself. The punctuation looks consistent to my untrained eyes. This is for a non-commercial family genealogy site, so I'd really like it to work :-) Obviously. LOL NOTE: These were redesigned by me from the original phpeasystart.com code to fit into a frame in a sidebar. The raw pages are at www.suleone.com/rinas/guestbook.php. To see it in context, go to www.suleone.com/rinas and it will be in the left sidebar. Any help you can provide is greatly appreciated. I'm a fairly smart gal, but this has got me stumped. In harmony, Rev. Su CODE FOR GUESTBOOK.PHP <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body class="oneColElsCtr"> <table width="165" border="0" cellpadding="3" cellspacing="1"> <form id="form1" name="form1" method="post" action="addguestbook.php"><tr> <td width="157">Name:</td> </tr> <tr> <td><input name="name" type="text" id="name" size="22" /></td> </tr> <tr> <td>Email:</td> </tr> <tr> <td><input name="email" type="text" id="email" size="22" /></td> </tr> <tr> <td valign="top">Comment:</td> </tr> <tr> <td valign="top"><textarea name="comment" cols="19" rows="4" id="comment"></textarea></td> </tr> <tr> <td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td> </tr> </form></table> <h6><strong><a href="viewguestbook.php">View Guestbook</a></strong></h6> </body> </html> CODE FOR ADDGUESTBOOK.PHP <?php $host="rinasfamilytree.db.3589040.hostedresource.com"; // Host name $username="rinasfamilytree"; // Mysql username $password=""; // Mysql password - this part is fine. $db_name="rinasfamilytree"; // Database name $tbl_name="guestbook"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("Sorry, I cannot connect to the server."); mysql_select_db("$db_name")or die("Sorry, I cannot select the database."); $datetime=date("y-m-d h:i:s"); //date time $sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')"; $result=mysql_query($sql); //check if query successful if($result){ echo "Thanks for commenting!"; echo "<BR>"; echo "<a href='viewguestbook.php'>See what you wrote.</a>"; // link to view guestbook page } else { echo "Sorry, there has been an error. Please refresh the page."; } mysql_close(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body class="oneColElsCtr"> </body> </html> CODE FOR VIEW GUESTBOOK.PHP <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> <!-- .style2 {font-size: 12px} --> </style> </head> <body class="oneColElsCtr"> <?php $host="rinasfamilytree.db.3589040.hostedresource.com"; // Host name $username="rinasfamilytree"; // Mysql username $password=""; // Mysql password - this part is fine. $db_name="rinasfamilytree"; // Database name $tbl_name="guestbook"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ ?> <table width="200" border="0"> <tr> <td><span class="style2"><? echo $rows['id']; ?> On <? echo $rows['datetime']; ?> <? echo $rows['name']; ?> said, "<? echo $rows['comment']; ?>"</span></td> </tr> </table> <? } mysql_close(); //close database ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/188925-my-add-to-guestbook-php-code-leaves-some-fields-blank/ Share on other sites More sharing options...
wildteen88 Posted January 18, 2010 Share Posted January 18, 2010 Add these three lines $name = mysql_real_escape_string($_POST['name']); $email = mysql_real_escape_string($_POST['email']); $comment = mysql_real_escape_string($_POST['comment']); Before these two lines $datetime=date("y-m-d h:i:s"); //date time $sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')"; Quote Link to comment https://forums.phpfreaks.com/topic/188925-my-add-to-guestbook-php-code-leaves-some-fields-blank/#findComment-997539 Share on other sites More sharing options...
revsu Posted January 18, 2010 Author Share Posted January 18, 2010 THANK YOU! I knew it was something simple and was beginning to lean toward definitions as the problem. I think I need to take a course from the W3C! LOL Blessings, Rev. Su Quote Link to comment https://forums.phpfreaks.com/topic/188925-my-add-to-guestbook-php-code-leaves-some-fields-blank/#findComment-997574 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.