Neuro Virus Posted June 7, 2006 Share Posted June 7, 2006 [code]<?$user = $_POST["user"];$comment = $_POST["comment"];echo "$user" . "<br>" . "$comment" . "<br><br>";?>[/code]Everythign works with no problems except one thing. The code doesnt save the input. In other words when I refresh my comment page it is blank. Nothing is saved. How do I fix this? Quote Link to comment https://forums.phpfreaks.com/topic/11375-trying-to-code-a-simple-guest-book/ Share on other sites More sharing options...
kenrbnsn Posted June 7, 2006 Share Posted June 7, 2006 Your code just displays the data passed from the form to the screen. Nothing more. If you want to save it you need to used either a flat file or a database.Ken Quote Link to comment https://forums.phpfreaks.com/topic/11375-trying-to-code-a-simple-guest-book/#findComment-42648 Share on other sites More sharing options...
Neuro Virus Posted June 7, 2006 Author Share Posted June 7, 2006 Okay, I changed it up a bit. I thought this would work but it doesn't. Why won't it save the comments :([code]<?mysql_connect("localhost","****","****");mysql_select_db("book");$user = $_POST[user];$comment = $_POST[comment];$sql="INSERT INTO comment (user,comment) VALUES ('$user','$comment')";mysql_query($sql);?></head><body><?$user = $_POST["user"];$comment = $_POST["comment"];echo "$user" . "<br>" . "$comment" . "<br><br>";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11375-trying-to-code-a-simple-guest-book/#findComment-42663 Share on other sites More sharing options...
.josh Posted June 7, 2006 Share Posted June 7, 2006 that does save your information in your database. now you must retrieve the information in order to get it to display later on. You have to connect to the database, select the information and then display it. example:[code]mysql_connect("localhost","****","****");mysql_select_db("book");$sql="select * from comment";$rs = mysql_query($sql);while ($comments = mysql_fetch_array($rs)) { echo $comments['user'] . " " . $comments['comment'] . "<br>";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11375-trying-to-code-a-simple-guest-book/#findComment-42670 Share on other sites More sharing options...
wildteen88 Posted June 7, 2006 Share Posted June 7, 2006 Seems like you dont quite understand how to use mysql and php together. If you dont I suggest you read through tutotials numbers 1 through to 9 over at [a href=\"http://www.php-mysql-tutorial.com/\" target=\"_blank\"]php-mysql-tutorial.com[/a]. Also you can have a go at tutorial number 12 too, as that shows how to create a simple guestbook.Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/11375-trying-to-code-a-simple-guest-book/#findComment-42738 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.