PHP syntax

Whats wrong with below? I got an error of "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource".

<?php

$zql="SELECT * FROM company WHERE bizid=$bizid";
$result3=mysql_query($zql);

if(mysql_num_rows($result3) == 1) {
      header("Location: index.php?bizid=$bizid");
}else {
        header("Location: index2.php?bizid=$bizid");
}
?>
LVL 2
rolandmyAsked:
Who is Participating?
 
Loganathan NatarajanLAMP DeveloperCommented:
then, you have to write db connectin and fix the issue like this,


<?php

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Not connected : ' . mysql_error());
}

// make foo the current db
$db_selected = mysql_select_db('foo', $link);
if (!$db_selected) {
    die ('Can\'t use foo : ' . mysql_error());
}


$zql="SELECT * FROM company WHERE bizid=$bizid";

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

$row_count = mysql_num_rows($result3);

echo $row_count;

if($row_count == 1) {
      header("Location: index.php?bizid=$bizid");
}else {
        header("Location: index2.php?bizid=$bizid");
}
?>

Open in new window

0
 
Loganathan NatarajanLAMP DeveloperCommented:
check your result?

print the query

echo $zql??

whether you have write query constructed and get the result

also $result3=mysql_query($zql);

to be $result3=mysql_query($zql) or die(mysql_error());
 
0
 
Loganathan NatarajanLAMP DeveloperCommented:
see the attached code
<?php

$zql="SELECT * FROM company WHERE bizid=$bizid";
$result3 = mysql_query($zql) or die(mysql_error());

if(mysql_num_rows($result3) == 1) {
      header("Location: index.php?bizid=$bizid");
}else {
        header("Location: index2.php?bizid=$bizid");
}
?>

Open in new window

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Loganathan NatarajanLAMP DeveloperCommented:
like this too,
<?php

$zql="SELECT * FROM company WHERE bizid=$bizid";

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

$row_count = mysql_num_rows($result3);

echo $row_count;

if($row_count == 1) {
      header("Location: index.php?bizid=$bizid");
}else {
        header("Location: index2.php?bizid=$bizid");
}
?>

Open in new window

0
 
rolandmyAuthor Commented:
No connection to database popped up.
0
 
Loganathan NatarajanLAMP DeveloperCommented:
you  must give correct details and connect the db before your other code
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.