Variable returning empty

Discussion in 'PHP' started by warsome, Jul 11, 2008.

Thread Status:
Not open for further replies.
  1. #1
    $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.
     
    warsome, Jul 11, 2008 IP
  2. revvi

    revvi Peon

    Messages:
    58
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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?
     
    revvi, Jul 11, 2008 IP
  3. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #3
    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 :D
     
    serialCoder, Jul 11, 2008 IP
  4. warsome

    warsome Guest

    Messages:
    500
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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 :)
     
    warsome, Jul 11, 2008 IP
  5. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #5
    hmm i dont see any mysql_fetch_row() or mysql_fetch_assoc() or even mysql_result(0, $rs)
     
    serialCoder, Jul 11, 2008 IP
  6. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #6
    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!");
    }
    ?>
     
    serialCoder, Jul 11, 2008 IP
  7. warsome

    warsome Guest

    Messages:
    500
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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.
     
    warsome, Jul 11, 2008 IP
Thread Status:
Not open for further replies.