0

Ok, I am trying to access my table via php. I have a successful connection to the server and a successful selection of the right database on the server. But I keep getting this error message when I try to run my query line through the mysql_fetch_array() finction:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/85/6905585/html/Web182/Final Project/instruments.php on line 33

This is the line that I am using to run my query.

$query = "SELECT uName, pwd FROM users WHERE uName == '$uName', pwd == '$pwd'";

Is there something wrong with my syntax? I am basically trying to compare the username and password in the database table to see if they match when the user entered in the login page. If it is correct, it will display the table of instruments ordered by the individual. Let me know if you need more info. =)

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by Dante2
0

Whenever you see "is not a valid MySQL result resource", that is a clear indication that the query failed.

You are probably executing something SIMILAR to: $result=mysql_query($query); If instead you had suffixed your query with "or die( mysql_error() );": $result=mysql_query($query) or die( "Unable to execute:<br> $query<br>". mysql_error() ); it would have given you a description of what you did wrong.

As for the actual problem, in PHP you check for equality using back-to-back equal signs, but NOT in SQL. You need just ONE equal sign: $query = "SELECT `uName`, `pwd` FROM `users` WHERE `uName` = '$uName', `pwd` = '$pwd'" ;

0

ok, here is the line of code rewritten: $query = "SELECT uName, pwd FROM users WHERE uName = '$uName', pwd = '$pwd'"; Unfortunately, even with the added die statements and error reporting, I am still at a loss. My error report says this:

unable to execute:
SELECT uName, pwd FROM users WHERE uName = 'billy', pwd = '123'
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' pwd = '123'' at line 1

And it says the same exact thing about billy when I remove the pwd criteria. I even tried running the query with the backward single quote marks around the field names and table name. Got the same error report. Anymore clues? I am positive that I have the right table and field names for the SELECT query. Checked it several times.

$uName = $_GET['uName'];
  $pwd = $_GET['pwd'];
  
  $dbc = mysql_connect(DBSERVER,USERNAME, PASSWORD);

  mysql_select_db('dante2');
  
  $query = "SELECT `uName`, `pwd` FROM `users` WHERE `uName` = '$uName', `pwd` = '$pwd'";
  
  $r = mysql_query($query) or die ("unable to execute:<br /> $query<br />". mysql_error());
  
  while ($row = mysql_fetch_array($r) or die ("unable to execute<br /> $query<br />". mysql_error()))
  {
  	if ($row['uName'] == $uName && $row['pwd'] == $pwd)
  	{
  		$_SESSION['uName'] = $uName;
  	}
  }

THe session stuff happens a little earlier in the script.

0

Your syntax is wrong at the comma. Condition clauses can be combined with "AND" and "OR" in SQL. Try

SELECT uName, pwd FROM users WHERE uName = '$uName' [U][B]AND[/B][/U] pwd = '$pwd'

Also look exactly where the MySQL error message tells that the error occurs. That's exactly the place: the wrong comma.

Edited by smantscheff: n/a

0

My apologies for the oversight. The WHERE clause currently has two conditions which are separated by a comma. Replace the comma with a space followed by the word AND followed by a space

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.