Jump to content

[SOLVED] Login script working strangley - Supplied Argument not valid - Works for some


busillis

Recommended Posts

Here is the warning: "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\ProjectName\login.php on line 29"

 

I have two users in the database, the strange thing is that is obtains the correct details from the database for one user, but not the other.  Both login credentials supplied are correct.

 

I've provided the code below, been looking at this for ages now and I cannot see it.  (Probably need more coffee, heh).

 

If anyone could help, it would be really appreciated!

 

<?php
//Starts database connection
require('dbconnect.php');

echo stripslashes($username=$_POST["username"]);
echo stripslashes($password=$_POST["password"]);
//Searches for a match on provided login credentials

$sql="SELECT customerid FROM regcustomer WHERE username='$username' and password='$password'";
//Stores all results matching the criteria
$result=mysql_query($sql);

//Determines how many results
$numberofresults=mysql_num_rows($result);

//Checks to ensure there is a unique match
if($numberofresults == 1) {
//Login a success so start session
session_start();
//gets customer id
echo $result;
while($row = mysql_fetch_array($result)) {
	echo $result=$row['customerid'];
}
//forms query to obtain name
$sql="SELECT * FROM customer WHERE customerid='$result'";
//stores the result of the query
$result=mysql_query($sql);
//gets the name from the array and sets the session var.
while($row = mysql_fetch_array($result)) {
	$_SESSION['customername']=$row['name'];
	$_SESSION['customerid']=$row['customerid'];
	echo $_SESSION['customername'];
	echo $_SESSION['customerid'];
  }
} else {
//login fail
echo "Fail";
}
//Ends database connection
mysql_close($con);
?>

Link to comment
Share on other sites

<?php
//Starts database connection
require('dbconnect.php');

$username=$_POST["username"];
$password=$_POST["password"];
//Searches for a match on provided login credentials

$sql="SELECT customerid FROM regcustomer WHERE username='$username' and password='$password'";
//Stores all results matching the criteria
$result=mysql_query($sql);

//Determines how many results
$numberofresults=mysql_num_rows($result);

//Checks to ensure there is a unique match
if($numberofresults == 1) {
//Login a success so start session
session_start();
//gets customer id
echo $result;
while($row = mysql_fetch_array($result)) {
	$customerid=$row['customerid'];
}
//forms query to obtain name
$sqlName="SELECT * FROM customer WHERE customerid='$customerid'";
//stores the result of the query
$resultName=mysql_query($sqlName);
//gets the name from the array and sets the session var.
while($rowName = mysql_fetch_array($resultName)) {
	$_SESSION['customername']=$rowName['name'];
	$_SESSION['customerid']=$rowName['customerid'];
	$_SESSION['customername'];
	$_SESSION['customerid'];
  }
} else {
//login fail
echo "Fail";
}
//Ends database connection
mysql_close($con);
?>

try that

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.