$result = mysql_query("SELECT Text FROM `Pages` WHERE Page = 'Projects'"); if($result) { $text = $row['Text']; } else { die("Error!"); } ?> PHP: Alright, so, above is the code I am using for my website. It is meant to set a variable ($text) to the value from my MySQL Database. The problem I am having, is that when I use the code: <? echo $text; ?> PHP: it doesn't show any text. What am I doing wrong? The value of Text in the database is "Test." It is probably something simple to fix, but I just can't wrap my head around it.
can you dump your sql database (just sample)? So we can have a look on the content. It may be wrong query or incomplete code. I know this sounds silly, do you have mysql_connect before that mysql_query right?
i think you are better off having a mysql_error() line in your main query line ex : $result = mysql_query("SELECT Text FROM `Pages` WHERE Page = 'Projects'") or die('cant select '.mysql_error()); if there are errors during query, you can easily debug it cheers
Yes, I do. Otherwise it would return as an error. My problem is that the Echo code doesn't show anything. Here is the information, as per requested. When I put Into PHPMyAdmin it shows the information I am after. Serialcoder- But I'm not having any errors right now with SQL. I will add that before my next upload, though. Thanks
do it like this $result = mysql_query("SELECT Text FROM `Pages` WHERE Page = 'Projects'"); if($result) { $row = mysql_fetch_assoc($result); $text = $row['Text']; } else { die("Error!"); } ?>
Oh, thanks mate This is my first project using mySQL that I have created from scrath. I tend to use just files, but this case calls for SQL.