Jump to content

Warning: mysql_num_rows(): supplied argument is not a valid MySQL?


Tylor_Famous

Recommended Posts

Hello,

 

I am getting the error and honestly have NO idea why? I am a bit new to PHP and MYSQL and hoped that someone might be able to look over my code and see if anyone might be able to help. The error that I get is as follows:

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /link/link/link/link on line 18

 


<?php

$user = $_GET['user'];
include ("db.php");
$table = 'mypagesites';

mysql_pconnect ($host, $user, $pass);
mysql_select_db ($database);

$query = "SELECT * FROM $table WHERE sitelink = '$user' ";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
extract($row);
?>

Link to comment
Share on other sites

I added the code and the error I get is:

 

Warning: extract(): First argument should be an array in /home/content/d/a/i/dailyquibbler/html/testing/mypageinfoform/mypagesite.php on line 15

 

Once again here is my code:

<?php


$user = $_GET['user'];

include ("db.php");
$table = 'mypagesites';

mysql_pconnect ($host, $user, $pass);
mysql_select_db ($database);

$query = "SELECT * FROM $table WHERE sitelink = '$user' ";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
$row = mysql_fetch_array($result);
extract($row);  



?>

Link to comment
Share on other sites

There is no mysql_num_rows() statement in the posted code, so there is no way it is the code that is generating the error in the first post. And if you removed the statement in an attempt to "stop" the error, that is no how programming works. Error messages exist for the purpose of telling you your code is not working. Removing a statement that is generating an error message does not fix the underlying problem, your code still won't work after you remove the statement. My guess would be (based on the query working with no error in the latest post) is that the result resource in the original mysql_num_rows() statement was the wrong name.

 

Your last post means that the query worked without an error but there was no row in the result set. You always need to check the result returned by a function call before blindly accessing data that might or might not exist. In this case, you either need to use the mysql_num_rows() to check if a row(s) were found or check if mysql_fetch_array() returned a false value (meaning no row was fetched) before attempting to use any data in the $row variable.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.