Page 1 of 1

supplied argument is not a valid MySQL-Link

Posted: Thu Dec 11, 2008 11:43 am
by pauls74462

Code: Select all

 
$link2 = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db("dbname", $link2);
 
$result = mysql_query("SELECT * FROM admin", $link);
$num_rows = mysql_num_rows($result);
 
echo "$num_rows Rows\n";
 
In the above code I get the bemow message on my screen.
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/mysite/public_html/folder1/folder2/login.php on line 39

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/mysite/public_html/folder1/folder2/login.php on line 40
Rows
Any one have any ideal why?

I have Google [ supplied argument is not a valid MySQL-Link ] with no help.

Paul

Re: supplied argument is not a valid MySQL-Link

Posted: Thu Dec 11, 2008 12:03 pm
by John Cartwright

Code: Select all

$link2 = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db("dbname", $link2) or die(mysql_error());
 
$result = mysql_query("SELECT * FROM admin", $link)  or die(mysql_error());
$num_rows = mysql_num_rows($result);
 
echo "$num_rows Rows\n";
Notice my usage of error reporting. This should tell you why it's failing. It is generally recommended you also include the error reporting, especially in a development environment.

Re: supplied argument is not a valid MySQL-Link

Posted: Thu Dec 11, 2008 1:20 pm
by califdon
For starters, you defined a database connection as $link2, but ran your query against $link. Do you suppose that might have created a problem?

Re: supplied argument is not a valid MySQL-Link

Posted: Thu Dec 11, 2008 4:14 pm
by pauls74462
califdon wrote:For starters, you defined a database connection as $link2, but ran your query against $link. Do you suppose that might have created a problem?
Well after 3 days of looking at the same code, (I never seen the (link2) error. Thanks for pointing it out. That helped, but didn't solve the problem 100%

Here is my new code

Code: Select all

 
// Make a MySQL Connection and check for errors
 
$link2 = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname, $link2) or die(mysql_error());
  
$result = mysql_query("SELECT * FROM admin", $link2) or die(mysql_error());
$num_rows = mysql_num_rows($result);
echo "<br />";
echo "<br />";
echo "$num_rows Rows\n"; // Check to see if it's getting anything from the db.
echo "<br />";
echo "<br />";
 
$username = $_POST['username']; 
$password = $_POST['password'];
 
echo $username; // echo the username from the db
echo "<br />";
echo "<br />";
echo $password;// Echo the password from the db
 
$result = mysql_query("select * from 'admin' where 'usersname' = $username and 'password' = $password", $link2);
(mysql_error());
// Make sure you actually get a result:
 
if (mysql_num_rows($result) != 1){  // Line #49
$error = "Bad Login";
 
//    include "login.html";
echo "Bad login";
} else {
    $_SESSION['username'] = "$username";
//    include "memberspage.php";
echo "Good login";
}
 
This is my new error:
December 11, 2008, 4:06 pm

2 Rows


Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/pauls744/public_html/schools/admin/login.php on line 49
Bad login
Thank you for your help

Re: supplied argument is not a valid MySQL-Link

Posted: Thu Dec 11, 2008 7:50 pm
by califdon
I suspect that you may misunderstand what $_POST variables are. Your code comment implies that you think it is coming from the database. $_POST variables result from <input> elements within an HTML form, when that form uses the current script as its action= parameter. Since you haven't shown any other code that has such a form, and your script is apparently not echoing anything for their values, I'd say your variables $username and $password have no values assigned to them. Looks like you have some real basic PHP to learn. Are you working from a textbook or an online tutorial or something? If you're just trying to pick it up by trying bits and pieces without any guidance, you're probably in for a l-o-n-g study.