PDA

View Full Version : Guestbook (MySQL and Values)



santaduane
01-11-2007, 11:01 AM
Hi everybody :)

I can't get my guestbook to work. I think it might be something with my values.
The date works fine, but name and message is just blank.

Is this right.. (working in dreamweaver)


$insertSQL = sprintf("INSERT INTO guestbook (`date`, name, message) VALUES (now(), '$name', '$message')",
GetSQLValueString($_POST['date'], "date"),
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['message'], "text"));

Hope you will help me :)

Titan85
01-11-2007, 12:00 PM
I am not sure if you have this somewhere and just didn't show it but, the first thing I see is that you need to define $message and $name. To do this, just add this at the top of your code:

$name = $_POST['name']; // Gets the value submitted for $name
$message = $_POST['message']; // Gets messageI hope that helps, I'll look into it further when I get home.
EDIT: Looking at it again, it seems that you did have something like that, but I am not sure if that way works, someone should know and post if it is right or not ;)

santaduane
01-11-2007, 12:27 PM
Thank you, thank you, thank you!! :)
It's working now..

santaduane
01-11-2007, 03:22 PM
By the way..

To begin with, Dreamweaver wrote it like this but then the date didn't work.

VALUES (%s, %s, %s)

Why is that and what does %s meen?

Titan85
01-11-2007, 06:43 PM
Hmm, I am not familiar with how dreamweaver generates php code, but I would guess that the %s in VALUES (%s, %s, %s) are where you place your variables. Like VALUES ('$value', '$value', '$value').

santaduane
01-11-2007, 07:50 PM
Okay.. but I still don't understand how the name and message could work with this, and not the date. :rolleyes:

$insertSQL = sprintf("INSERT INTO guestbook (`date`, name, message) VALUES (%s, %s, %s)"

Titan85
01-11-2007, 07:57 PM
O, I didn't see that you said the date stopped working, you need to define what the date is in the same way:

$date = date('F j, Y'); Now your sql code should be like this

mysql_querry("INSERT INTO `guestbook` (date, name, message) VALUES ('$date', '$name', '$message')");Hope this helps out :)