PHP guestbook doesn't add entries to database.

Hello,

I’ve got a little problem with the php guestbook i’ve been working on. I use the guestbook with a database in PHPmyadmin. I’ve got the files to work mostly correct, it shows the guestbook (viewguestbook.php) when entering that section, lets you add a new entry (addguestbook.php). After making a new entry in the guestbook when you’d click submit it shows a blank page with ‘gelukt!’ (succesful!) and takes you to the guestbook where the new entry is added. One small problem, the entry is entirely blank but for the time/date. It does show the fields for name, email and message but there’s nothing next to that.
I’ve shown the PHP code below

I’ve set up the database properly i thought, but my guess is i went wrong at that part…

http://www.mediafire.com/imgbnc.php/a6f6f7c6be1ce2be117021f739aac3f739bb6bc681d055160f7ef78fcbeac2776g.jpg

PHP:

[php]

<?php $host="db.devuilnisprinses.nl"; // Host name $username="md223309db172500"; // Mysql username $password="Nl3YT1lz"; // Mysql password $db_name="md223309db172500"; // Database name $tbl_name="guestbook"; // Table name

// Connect to server and select database.
mysql_connect("$host", “$username”, “$password”)or die(“cannot connect server “);
mysql_select_db(”$db_name”)or die(“cannot select DB”);

$datetime=date(“y-m-d h:i:s”); //date time

$sql=“INSERT INTO $tbl_name(name, email, comment, datetime)VALUES(’$name’, ‘$email’, ‘$comment’, ‘$datetime’)”;
$result=mysql_query($sql);

//check if query successful
if($result){
echo “Gelukt!”;
echo “
”;
echo “naar het gastenboek.”; // link to view guestbook page
}

else {
echo “Oeps! er ging iets fout…”;
}

mysql_close();
?>

[/php]

[php]

<? include 'head.php';?>
Gastenboek | Laat een bericht achter!

<?php $host="db.devuilnisprinses.nl"; // Host name $username="md223309db172500"; // Mysql username $password="Nl3YT1lz"; // Mysql password $db_name="md223309db172500"; // Database name $tbl_name="guestbook"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ ?>
Naam : <? echo $rows['name']; ?>
Email : <? echo $rows['email']; ?>
Bericht : <? echo $rows['comment']; ?>
Datum en tijd : <? echo $rows['datetime']; ?>

<? } mysql_close(); //close database ?>
<? include 'footer.php';?> [/php]

[php]

<? include 'head.php';?>
Gastenboek - Laat een berichtje achter!
Naam :
Email :
Bericht :
   
Gastenboek Bekijken
<? include 'footer.php';?> [/php]

the first thing you need to do is change the password and name of your database now that every hacker in the world can see it :o :o :o :o :o :o :o :o

well it looks like you are sending the database empty variables
[php]$sql=“INSERT INTO $tbl_name(name, email, comment, datetime)VALUES(’$name’, ‘$email’, ‘$comment’, ‘$datetime’)”;[/php]

if you look at $name, email, $comment, and $datetime, well NOWHERE do you say what each of those are so the database has no idea what those variables are supposed to be!
I would guess you need to put this whole piece of code just before the INSERT query:
[php]
$name=strip_tags($_POST[‘name’]);
$email=strip_tags($_POST[‘email’]);
$comment=strip_tags($_POST[‘comment’]);
$name=mysql_escape_string($name);
$email=mysql_escape_string);
$comment=mysql_escape_string(comment);
$datetime=now();

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service