Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-13-2011, 06:13 AM   PM User | #1
magician1983
New Coder

 
Join Date: May 2011
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
magician1983 is an unknown quantity at this point
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..
magician1983 is offline   Reply With Quote
Old 05-13-2011, 06:31 AM   PM User | #2
bullant
Banned

 
Join Date: Feb 2011
Posts: 2,699
Thanks: 13
Thanked 395 Times in 395 Posts
bullant is on a distinguished road
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.

bullant is offline   Reply With Quote
Old 05-13-2011, 06:44 AM   PM User | #3
M2D
New to the CF scene

 
Join Date: Jan 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
M2D is an unknown quantity at this point
remove this line and try it
PHP Code:
$support_pull mysql_fetch_array($query) or die(mysql_error()); 
M2D is offline   Reply With Quote
Old 05-13-2011, 06:55 PM   PM User | #4
magician1983
New Coder

 
Join Date: May 2011
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
magician1983 is an unknown quantity at this point
I tried it and still am not getting results. Any other ideas?
magician1983 is offline   Reply With Quote
Old 05-13-2011, 08:14 PM   PM User | #5
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 05-14-2011, 03:49 AM   PM User | #6
magician1983
New Coder

 
Join Date: May 2011
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
magician1983 is an unknown quantity at this point
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.
magician1983 is offline   Reply With Quote
Old 05-14-2011, 04:54 AM   PM User | #7
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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).
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
loop, mysql, output, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:17 AM.


Advertisement
Log in to turn off these ads.