seb hughes Posted May 13, 2007 Share Posted May 13, 2007 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>'; } Quote Link to comment https://forums.phpfreaks.com/topic/51216-solved-echo-problem/ Share on other sites More sharing options...
marmite Posted May 13, 2007 Share Posted May 13, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/51216-solved-echo-problem/#findComment-252227 Share on other sites More sharing options...
seb hughes Posted May 13, 2007 Author Share Posted May 13, 2007 Now people say they don't see any comments at all. Quote Link to comment https://forums.phpfreaks.com/topic/51216-solved-echo-problem/#findComment-252307 Share on other sites More sharing options...
kenrbnsn Posted May 13, 2007 Share Posted May 13, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/51216-solved-echo-problem/#findComment-252343 Share on other sites More sharing options...
seb hughes Posted May 14, 2007 Author Share Posted May 14, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/51216-solved-echo-problem/#findComment-253041 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.