Jump to content

PHP Login


vasoftwaresolutions

Recommended Posts

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/pacifij1/public_html/bluewavesvirtual/checklogin.php on line 23

 

Does any know what that means.. here is my code

 

<?php
$host="localhost"; // Host name 
$username="pacifij1_blue"; // Mysql username 
$password="8336994895"; // Mysql password 
$db_name="pacifij1_blue"; // Database name 
$tbl_name="pilot"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from signup form 
$callsign=$_POST['callsign']; 
$password=$_POST['password']; 
$first_name=$_POST['first_name']; 
$last_name=$_POST['last_name']; 


$sql="SELECT * FROM $tbl_name WHERE callsign='$callsign' and password='$password'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("callsign");
session_register("password"); 
session_register("first_name"); 
session_register("last_name"); 
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Loading</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
</head>

<body>
</body>
</html>

Link to comment
Share on other sites

  • Replies 58
  • Created
  • Last Reply

ok so you're using sessions?

 

If you are using sessions on every page of your site... then do this...

 

the first and second lines should be...

 

<?

session_start();

session_destroy();

 

and then right before you do the session register, put "session_start();" before it...

Link to comment
Share on other sites

Change:

$count=mysql_num_rows($result);

To:

$count=mysql_numrows($result);

its giving me this now

"Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/pacifij1/public_html/bluewavesvirtual/checklogin.php on line 23"

 

Is that first set of code you gave us the checklogin.php?

Link to comment
Share on other sites

Replace

 

$sql="SELECT * FROM $tbl_name WHERE callsign='$callsign' and password='$password'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

 

with

 

$sql="SELECT * FROM $tbl_name WHERE callsign='$callsign' and password='$password'";
$result=mysql_query($sql) or die(mysql_error());

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

Link to comment
Share on other sites

ohhhhhhhhh. i think i might see it...

 

try this..

 

$sql="SELECT * FROM $tbl_name WHERE callsign='$callsign' and password='$password'";

$result=mysql_query($sql) or die(mysql_error());

 

that will show you errors in your query, and that might be the root of the problem...

Link to comment
Share on other sites

ohhhhhhhhh. i think i might see it...

 

try this..

 

$sql="SELECT * FROM $tbl_name WHERE callsign='$callsign' and password='$password'";

$result=mysql_query($sql) or die(mysql_error());

 

that will show you errors in your query, and that might be the root of the problem...

 

Wow, thats just what I posted.

 

@derick: your not solving the problem by doing that, infact that makes it worst.

Link to comment
Share on other sites

mysql_numrows is an old depreciated function alias. Don't use it and don't suggest it as a solution, as it has nothing to do with the error.

 

Your mysql_query is failing, but your code has no error checking to get it to tell you what the problem is. You might have a session problem as well, because session_register() is also an old and depreciated function and only works when register globals are on.

 

To find your actual problem, change your mysql_query to the following -

 

$result=mysql_query($sql) or die("The fricken query has no error checking: " . mysql_error());

 

Edit: Third times the charm (error checking should have been the first suggestion.)

Link to comment
Share on other sites

check your spelling of everything, the code AND the db...

and if your table name is always "pilot" in this query, then just change it to `pilot` in the query.... less room for error...

 

idk... it seems redundant to use a variable for something that is always the same...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • 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.