Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with PHP code

    What´s wrong with this code? I don´t even get an error message, just a blank page. Thanks a lot for your help!



    include ('connectionfile.php');
    $sql_select = ("SELECT var1, var2 from table WHERE username = '".$_SESSION['username']."'");
    $result = mysql_query($sql_select);

    if ($result){
    if (mysql_num_rows($result)== 0){
    echo ("<br /> No records returned.");
    }
    else{

    echo("<table><tr><td>Var1</td><td>var2</td></tr>");

    while ($row = mysql_fetch_array($result)) {
    echo("<tr><td>" . $row['var1'] . "</td><td>" . $row['var2'] . "</td></tr>");
    }
    echo ("</table>");
    }
    }

  • #2
    Regular Coder
    Join Date
    Feb 2003
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts
    maybe something wrong with 'connectionfile.php' file?

  • #3
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Do you have an errors log assigned? If so, look in there. If not, assign one.
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #4
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    And a friendly tip,

    when debuggin, add lots of print statements. It seems to be the easiest way to figure out why code is mis behaving.

    In this case, you have
    Code:
    if($result) {
        // do lots
    }
    but you don't have an "else { print "no results";}"
    which may help you identify the problem as being a bad query.

    So, you could do a "print $sql_select;" statment and try to execute that on the db to see if you actually get the data your expecting.

    I always like to add print statments then comment them out / delete them when I'm done.
    Just a tip

  • #5
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    621
    Thanks
    0
    Thanked 6 Times in 6 Posts
    also possible that your sql query isn't returning anything.

    Try this:
    PHP Code:
    include ('connectionfile.php');
    $sql_select = ("SELECT var1, var2 FROM table WHERE username = '".$_SESSION['username']."'");
    $result mysql_query($sql_select);

    if (
    $result) {
       if (
    mysql_num_rows($result)== 0) {
          echo (
    "<br /> No records returned.");
       } else {
          echo(
    "<table><tr><td>Var1</td><td>var2</td></tr>");
          
          while (
    $row mysql_fetch_assoc($result)) {
             echo(
    "<tr><td>" $row['var1'] . "</td><td>" $row['var2'] . "</td></tr>");
          }
          echo (
    "</table>");
       }
    } else { print 
    "Whoops...nothing returned from SQL Statement!";} 
    I'd also suggest viewing the HTML source of that "blank" page. Make sure it isn't really blank....it may be writing that table information to it....and not even telling you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •