Login Problem (mysql_num_rows(): supplied argument is......)
Posted: Wed Dec 01, 2004 4:03 am
The script spits out the following errors:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/php32/public_html/login2.php on line 13
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/php32/public_html/login2.php on line 14
Login Fail.
Not sure why this is doing this i am new to php so it's not one i've encountred before. Any help would be appriacated. Code is below:
<?php
include "./db.inc";
$register_script ="./register.php";
function login($username, $password){
global $default_dbname;
$link_id = db_connect($default_dbname);
$query = 'select * from customers '
."where username= '$username' "
." and password= '$password'";
$result = mysql_query($query, $db_connect);
if(!mysql_num_rows($result)) return 0;
else{
$query_data = mysql_fetch_row($result);
return $query_data[0];
}
}
function login_form() {
global $PHP_SELF;
?>
<html>
<head>
<title>Login Form</title>
</head>
<body>
<form method="post" action="<? echo $PHP_SELF ?>">
<div align="center"><center>
<p>Login</p>
<table width="731" height="221" border ="1" cellpadding="2">
<!--DWLayoutTable-->
<tr>
<th width="155" align="right" nowrap>Username: </th>
<td width="115" nowrap> <input type="text" name="username" size="15">
</td>
<td width="356"> </td>
</tr>
<tr>
<th width="155" align="right" nowrap>Password: </th>
<td width="115" nowrap> <input type="password" name="password" size="15">
</td>
<td></td>
</tr>
<tr>
<td height="75" colspan="2" align="center" nowrap>
<input type="submit" value="login" name="submit">
<input type="reset" value="reset" name="reset"> </td>
<td><a href="/~php32/index.php">Home</a> | <a href="/~php32/register.php">Register</a> | <a href="/~php32/logout.php">Logout</a> | <a href="/~php32/login.php">Login </a></td>
</tr>
</table>
</center></div>
</form>
</body>
</html>
<?
}
session_start();
if (!isset($username)) {
login_form();
exit;
}
else {
function validation_check($username){
global $default_dbname;
$link_id = db_connect($default_dbname);
$query = 'select validated from customers '
."where username ='$username'";
$result = mysql_query($query);
if ($result != 1) {
echo "This account has not been validated, you need to validate it before you can use it";
}
}
function check_rank($username){
global $default_dbname;
$link_id = db_connect($default_dbname);
$query = 'select rank from customers '
."where username ='$username'";
$result = mysql_query($query);
if($result >=2){
Header ("Location: admin.php");
exit;
}
}
session_register("username", "password");
$username = login($username, $password);
if(!$username) {
session_unregister("username");
session_unregister("password");
echo "Login Fail." ;
exit;
}
else echo "Welcome, $username";
}
?>
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/php32/public_html/login2.php on line 13
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/php32/public_html/login2.php on line 14
Login Fail.
Not sure why this is doing this i am new to php so it's not one i've encountred before. Any help would be appriacated. Code is below:
<?php
include "./db.inc";
$register_script ="./register.php";
function login($username, $password){
global $default_dbname;
$link_id = db_connect($default_dbname);
$query = 'select * from customers '
."where username= '$username' "
." and password= '$password'";
$result = mysql_query($query, $db_connect);
if(!mysql_num_rows($result)) return 0;
else{
$query_data = mysql_fetch_row($result);
return $query_data[0];
}
}
function login_form() {
global $PHP_SELF;
?>
<html>
<head>
<title>Login Form</title>
</head>
<body>
<form method="post" action="<? echo $PHP_SELF ?>">
<div align="center"><center>
<p>Login</p>
<table width="731" height="221" border ="1" cellpadding="2">
<!--DWLayoutTable-->
<tr>
<th width="155" align="right" nowrap>Username: </th>
<td width="115" nowrap> <input type="text" name="username" size="15">
</td>
<td width="356"> </td>
</tr>
<tr>
<th width="155" align="right" nowrap>Password: </th>
<td width="115" nowrap> <input type="password" name="password" size="15">
</td>
<td></td>
</tr>
<tr>
<td height="75" colspan="2" align="center" nowrap>
<input type="submit" value="login" name="submit">
<input type="reset" value="reset" name="reset"> </td>
<td><a href="/~php32/index.php">Home</a> | <a href="/~php32/register.php">Register</a> | <a href="/~php32/logout.php">Logout</a> | <a href="/~php32/login.php">Login </a></td>
</tr>
</table>
</center></div>
</form>
</body>
</html>
<?
}
session_start();
if (!isset($username)) {
login_form();
exit;
}
else {
function validation_check($username){
global $default_dbname;
$link_id = db_connect($default_dbname);
$query = 'select validated from customers '
."where username ='$username'";
$result = mysql_query($query);
if ($result != 1) {
echo "This account has not been validated, you need to validate it before you can use it";
}
}
function check_rank($username){
global $default_dbname;
$link_id = db_connect($default_dbname);
$query = 'select rank from customers '
."where username ='$username'";
$result = mysql_query($query);
if($result >=2){
Header ("Location: admin.php");
exit;
}
}
session_register("username", "password");
$username = login($username, $password);
if(!$username) {
session_unregister("username");
session_unregister("password");
echo "Login Fail." ;
exit;
}
else echo "Welcome, $username";
}
?>