Tylor_Famous Posted March 22, 2008 Share Posted March 22, 2008 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); ?> Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 22, 2008 Share Posted March 22, 2008 $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); // infornative message Quote Link to comment Share on other sites More sharing options...
Tylor_Famous Posted March 22, 2008 Author Share Posted March 22, 2008 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); ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 22, 2008 Share Posted March 22, 2008 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. Quote Link to comment Share on other sites More sharing options...
Tylor_Famous Posted March 23, 2008 Author Share Posted March 23, 2008 PFMaBiSmAd Thanks so much. I was able to take what you said and fix the problem! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.