Jump to content

php help_connecting sql database


ma5ect

Recommended Posts

Hi,

 

I 'am trying to connect my sql database with my webpage for users log in. i have got this script so far but i keep getting the following error message which i cannot figure out..

 

could any1 help..

 

error:Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\checklogin.php on line 18

Wrong Username or Password

 

code:

<?

 

$hostname_mysql_connect = "localhost";

$database_mysql_connect = "website_members";

$username_mysql_connect = "root";

$password_mysql_connect = "******";

$tblname_mysql_connect ="members";

 

$mysql_connect = mysql_pconnect($hostname_mysql_connect, $username_mysql_connect, $password_mysql_connect, $tblname_mysql_connect) or trigger_error(mysql_error(),E_USER_ERROR);

mysql_select_db($database_mysql_connect) or die(mysql_error());

 

$myusername = $_POST['myusername'];

$mypassword = $_POST['mypassword'];

 

$sql = "SELECT * FROM $tblname_mysql_connect WHERE username= '$myusername' and password='$mypassword'";

$result = mysql_query($sql);

 

$count = mysql_num_rows($result); (line 18)

if($count==1) {

session_register("myusername");

session_register("mypassword");

header("location:login_success.php");

}

else {

echo "Wrong Username or Password";

}

 

?>

 

 

many thanx

 

Link to comment
Share on other sites

Looks ok from what I can tell, but I know mysql_num_rows is finicky... but I would try taking out the line space between these two lines... See what happens...

 

$result = mysql_query($sql);
$count = mysql_num_rows($result);

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.