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
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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.