Help my guestbook, please..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ayoksus
Forum Newbie
Posts: 14
Joined: Tue Feb 13, 2007 2:51 pm

Help my guestbook, please..

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Descriptive Subjects

Post 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.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post 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>";
}
?>
Post Reply