?
Solved

PHP syntax

Posted on 2011-10-11
6
Medium Priority
?
264 Views
Last Modified: 2012-05-12
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");
}
?>
0
Comment
Question by:rolandmy
  • 5
6 Comments
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 36947087
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
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 36947088
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
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 36947090
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:rolandmy
ID: 36947108
No connection to database popped up.
0
 
LVL 36

Accepted Solution

by:
Loganathan Natarajan earned 500 total points
ID: 36947117
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
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 36947122
you  must give correct details and connect the db before your other code
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question