Jump to content


Photo

trying to code a simple guest book...


  • Please log in to reply
4 replies to this topic

#1 Neuro Virus

Neuro Virus
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 07 June 2006 - 12:28 AM

<?
$user = $_POST["user"];
$comment = $_POST["comment"];
echo "$user" . "<br>" . "$comment" . "<br><br>";
?>
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?

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 07 June 2006 - 02:28 AM

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

#3 Neuro Virus

Neuro Virus
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 07 June 2006 - 04:28 AM

Okay, I changed it up a bit. I thought this would work but it doesn't. Why won't it save the comments :(
<?
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>";
?>


#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 07 June 2006 - 05:04 AM

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:

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>";
}

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 07 June 2006 - 10:31 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users