Hank Wilson
Hank Wilson

Reputation: 519

Select Statement Not Showing Anything

I have the following statement in my code

$query3="select * from students where student_name = '$referredby'";
$result3=mysql_query($query3);
$num_rows = mysql_num_rows($result3);
if($num_rows==0){
    echo "Nobody Found";
    die();
}else{
    echo "Number Of Rows ".$num_rows;
    die();
}       

If I do an echo for the value of the $referredby variable prior to running the query, it shows me the correct value for the $referredby variable, and when I look at the table there is a student name that matches that value.

However when I run the program it blows right on by the if statement where I test for number of rows returned.

I'm missing something but can't seem to locate it, any help is appreciated.

Upvotes: 0

Views: 585

Answers (1)

rws907
rws907

Reputation: 777

Try replacing this:

$result3=mysql_query($query3);

With this

$result3 = mysql_query($query3) or die(mysql_error());

And see if you get any MySQL errors output to your screen. If you don't then the query obviously worked and everything in the SQL is correct. Out of curiosity, what do you have the Field Type of the column storing the name set to? Text? Varchar? Blob? It SHOULDN'T matter but the more info you can give us the better.

Upvotes: 2

Related Questions