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 7 of 7
  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    I need help with the following PHP code in determining why no results are returning

    Here is the code:

    PHP Code:
    <?php
    $con 
    mysql_connect("localhost""root"'');

    if (!
    $con)
    {
        die(
    'Cannot make a connection');
    }


    mysql_select_db('yumbox_table'$con) or die('Cannot make a connection');
    session_start();
    ini_set('session.bug_compat_warn'0);
    ini_set('session.bug_compat_42'0);

    $_SESSION['user_name'] = $_POST['user_name'];
    $_SESSION['password'] = $_POST['password'];
    $user_name mysql_real_escape_string($_POST['user_name']);
    $password mysql_real_escape_string($_POST['password']);




    $data mysql_query("SELECT * from users where user_name = '$user_name' AND password = '$password'") or die(mysql_error());
    $row mysql_fetch_assoc($data); 


    $count mysql_numrows($data);

    if (
    $count==1)
    {


    if (
    $row['user_type']=="Customer")
    {
        echo 
    "Welcome Customer";
        echo 
    "</br>";
        echo 
    $row['first_name']. " ";
        echo 
    $row['last_name'];
        echo 
    "</br>";
    }

    if (
    $row['user_type']=="Support Staff")
    {
        echo 
    "Welcome Support Staff";
        echo 
    "</br>";
        echo 
    $row['first_name']. " ";
        echo 
    $row['last_name'];
        echo 
    "</br>";
        echo 
    "Here are a list of open tickets:  ";
        
        
    $query mysql_query("SELECT users.id, users.email, users.first_name, users.last_name,  users.user_type, users.user_name, users.password, users.problem_id, yumbox_customer_inquiry.problem_id, yumbox_customer_inquiry.customer_last_name, yumbox_customer_inquiry.customer_first_name, yumbox_customer_inquiry.customer_email, yumbox_customer_inquiry.problem_body, yumbox_customer_inquiry.category_id, yumbox_customer_inquiry.problem_status, yumbox_customer_inquiry.problem_solution  from yumbox_customer_inquiry, users where users.problem_id = yumbox_customer_inquiry.category_id AND yumbox_customer_inquiry.problem_solution = ' '") or die (mysql_error());
        
    $result mysql_fetch_assoc($query);
        
    $support_pull mysql_fetch_array($query) or die(mysql_error());
        
    $_SESSION['tabledata'] = $result;
        
        [
    B]while($support_pull mysql_fetch_array($query))
        {
            echo 
    "Customer First Name:  ";
            echo 
    $support_pull['customer_first_name'];
            echo 
    "</br>";
            echo 
    "Customer Last Name:  ";
            echo 
    $support_pull['customer_last_name'];
            echo 
    "</br>";
            echo 
    "Description of Problem:  ";
            echo 
    $support_pull['problem_body'];
            echo 
    "</br>";    
        }
        [/
    B]
        
    }

    }
    else 
    {
        echo (
    "I am sorry but this login is incorrect.  Please try again");
    }







        




    mysql_close($con);
    ?>
    The portions in bold are the issue. After retrieving the results from the tables listed in $query, there is suppose to be a loop (again, listed in bold) that retrieves all the relevant results and display them onscreen. However, I receive nothing. Now I know that it's not because there is nothing in the mysql table being referenced. So if anyone out there has an idea as to what is wrong, I would greatly appreciate it.

    Thanks!
    Last edited by Inigoesdr; 05-13-2011 at 10:46 PM.

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Looks like you just need to do some Basic Debugging 101 to find your errors.

    As a starting point have a read up on what mysql_fetch_assoc() returns and your problem(s) should become clear.


  • #3
    M2D
    M2D is offline
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    remove this line and try it
    PHP Code:
    $support_pull mysql_fetch_array($query) or die(mysql_error()); 

  • #4
    New Coder
    Join Date
    May 2011
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I tried it and still am not getting results. Any other ideas?

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    do you receive either a PHP error or mysql error (or perhaps just a white screen), or is it just that no records are iterated? If its the latter, than you simply have no results matching that criteria. If its the former, post the error if its available, and if its a white screen use
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    at the top of the page to have it show you the errors (or check the error log).

    Now, two things I can say: you don't need to die mysql_fetch_*. In fact I wouldn't ever do this, as its typically used for a control within a while loop, and will continue until it hits false. If you add an or die() to it, it will cause it to fail when it shouldn't.
    Second, you are aware you are starting on the third (if it exists) record of the resultset correct?
    PHP Code:
        $result mysql_fetch_assoc($query);
        
    $support_pull mysql_fetch_array($query) or die(mysql_error());
        
    $_SESSION['tabledata'] = $result;
        
        while(
    $support_pull mysql_fetch_array($query)) 
    You have a call to fetch_assoc which will iterate to the second record, and the a call to fetch_array which will iterate past the second to the third record. Now the fetch_array within the while loop begins on the third record, or fails to evaluate if it has no third record.

  • #6
    New Coder
    Join Date
    May 2011
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    It does not display error messages, it displays no results. It should though, because the MY_SQL query statement in question lists parameters in it that should match certain data within the two tables listed.

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by magician1983 View Post
    It does not display error messages, it displays no results. It should though, because the MY_SQL query statement in question lists parameters in it that should match certain data within the two tables listed.
    Then there is no problem here. The problem is your query data, not a problem with PHP. Just because a table has columns you are requesting does not mean that it matches your definition of a where clause.
    Also mentioned, you are starting on the third record, but you did not touch base on that in your last reply.
    Copy the created query by printing it out before processing it and pasting it into querybrowser or cli mysql connection. I'm betting you have less than 3 record (which may or may not be zero).


  •  

    Tags for this Thread

    Posting Permissions

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