Jump to content

Archived

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

Neuro Virus

trying to code a simple guest book...

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?

Share this post


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

Share this post


Link to post
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]

Share this post


Link to post
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]

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.