busillis Posted March 15, 2009 Share Posted March 15, 2009 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 https://forums.phpfreaks.com/topic/149500-solved-login-script-working-strangley-supplied-argument-not-valid-works-for-some/ Share on other sites More sharing options...
busillis Posted March 15, 2009 Author Share Posted March 15, 2009 db had some invalid data.... DOH!!! Link to comment https://forums.phpfreaks.com/topic/149500-solved-login-script-working-strangley-supplied-argument-not-valid-works-for-some/#findComment-785094 Share on other sites More sharing options...
busillis Posted March 15, 2009 Author Share Posted March 15, 2009 However, I still get the warning... I've added or die ('Error: '.mysql_error ()); but its not giving any thing useful back! Link to comment https://forums.phpfreaks.com/topic/149500-solved-login-script-working-strangley-supplied-argument-not-valid-works-for-some/#findComment-785096 Share on other sites More sharing options...
abch624 Posted March 15, 2009 Share Posted March 15, 2009 <?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 https://forums.phpfreaks.com/topic/149500-solved-login-script-working-strangley-supplied-argument-not-valid-works-for-some/#findComment-785100 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.