supplied argument is not a valid MySQL-Link

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
pauls74462
Forum Newbie
Posts: 16
Joined: Tue Jun 10, 2008 8:13 pm

supplied argument is not a valid MySQL-Link

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: supplied argument is not a valid MySQL-Link

Post 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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: supplied argument is not a valid MySQL-Link

Post 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?
pauls74462
Forum Newbie
Posts: 16
Joined: Tue Jun 10, 2008 8:13 pm

Re: supplied argument is not a valid MySQL-Link

Post 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
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: supplied argument is not a valid MySQL-Link

Post 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.
Post Reply