Page 1 of 1

Help my guestbook, please..

Posted: Sat Jul 07, 2007 6:02 pm
by ayoksus
Hi,

I tried to make a guestbook with php, but I got this problem.

I can put my messages to database, but when I want to show my message i only got this message.
Guest's comments
Name: Array [name]
E-mail: Array [email]
Messages: Array [message]

I use this script to show the message.

Code: Select all

<?php
echo "<H3>Guest's comments</H3>";

include "guestbook_connection.php";
$show=mysql_query("SELECT * FROM guest ORDER BY guest_number DESC");

while ($data=mysql_fetch_array($show))
{
	echo "Name: $data [name]<br>";
	echo "E-mail: $data [email]<br>";
	echo "Message: $data [messages]<br>";
}
?>
Could anybody help me out?

Thx
ayoksus

Posted: Sat Jul 07, 2007 6:17 pm
by superdezign
Because you are using quotes, PHP sees that space as a literal character. Either get rid of the space in between the array name and the index, or don't put it in quotes.

Also, use single quotes in index names for associative arrays.

Descriptive Subjects

Posted: Sat Jul 07, 2007 7:25 pm
by feyd
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.

Posted: Sun Jul 08, 2007 2:31 am
by dibyendrah
Always seperate PHP variables from strings under double quotes so as to debug easily.

Code: Select all

<?php
echo "<H3>Guest's comments</H3>";

include "guestbook_connection.php";
$show=mysql_query("SELECT * FROM guest ORDER BY guest_number DESC");

while ($data=mysql_fetch_array($show))
{
        echo "Name: ".$data['name']."<br>";
        echo "E-mail: ".$data[email]."<br>";
        echo "Message: ".$data[messages]."<br>";
}
?>