Jump to content

trying to code a simple guest book...


Neuro Virus

Recommended Posts

[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?
Link to comment
https://forums.phpfreaks.com/topic/11375-trying-to-code-a-simple-guest-book/
Share on other sites

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]
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]
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.