Jump to content

Recommended Posts

I'm running a mysql query to get comments out of my database but I see it fine, but some people get this:

 

"; echo "Message: ".$row['message']." 

"; } ?>  

 

The code im using to get the data/display it is:

 

$query = mysql_query("SELECT * FROM guestbook WHERE `show` =1") or die(mysql_error());  
while($row = mysql_fetch_array($query)) {
	echo 'Name: ';
	echo $row['name'];
	echo '<br>';
	echo 'Message: ';
	echo $row['message'];
	echo'<br><br>';


}

Link to comment
https://forums.phpfreaks.com/topic/51216-solved-echo-problem/
Share on other sites

Can't see anything immediately obvious, but have the following thoughts.

 

First question: when you say "some people get this", do you mean that that code is actually printed to the webpage (visible on the page, so echo'd)?

 

I would try:

1) replace $row['name'] with $row[name] and the same for the other similar line.

2) get rid of separate statements, so

echo "Name: .$row[name].<br>.Message: .$row[message].<br><br>";

this would perhaps simplify things. can't immediately spot fault. sorry!

Link to comment
https://forums.phpfreaks.com/topic/51216-solved-echo-problem/#findComment-252227
Share on other sites

The other poster was on the right track, but got the syntax wrong. Try this:

<?php

$query = "SELECT * FROM guestbook WHERE `show` =1";
$rs = mysql_query($query) or die("Problem with the query: <pre>$query</pre><br>" . mysql_error());  
while($row = mysql_fetch_array($query))
	echo 'Name: ' . $row['name'] . '<br>Message: ' . $row['message'] . '<br><br>';
?>

 

Is there any other code in your script that could be causing the problem.

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/51216-solved-echo-problem/#findComment-252343
Share on other sites

You have a tiny mistake in your code:

 

<?php

$query = "SELECT * FROM guestbook WHERE `show` =1";
$rs = mysql_query($query) or die("Problem with the query: <pre>$query</pre><br>" . mysql_error());  
while($row = mysql_fetch_array($query) 
	echo 'Name: ' . $row['name'] . '<br>Message: ' . $row['message'] . '<br><br>';

?>

 

It should be:

 

<?php

$query = "SELECT * FROM guestbook WHERE `show` =1";
$rs = mysql_query($query) or die("Problem with the query: <pre>$query</pre><br>" . mysql_error());  
while($row = mysql_fetch_array($rs)) {
	echo 'Name: ' . $row['name'] . '<br>Message: ' . $row['message'] . '<br><br>';
}
?>

 

I got it working now, I think it might be because my subdomain was using php5, but that shouldn't really make a difference, but I changed it to 4 and it worked, or it could have been because or a bad htaccess file. Anyway it works. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/51216-solved-echo-problem/#findComment-253041
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.