newbienewbie Posted March 1, 2007 Share Posted March 1, 2007 NEWBIE: I want to authenticte the entered username with the password sttored in db. but when i enter correct username and password it gives me error Query failed: Unknown column 'xyz' in 'where clause' plz chk this query $query = "SELECT pass FROM $my_table WHERE user=$col_value"; and following code <?php $mysql_host='localhost'; $mysql_user='xyz'; $mysql_password='xyz'; $my_database='xyz'; $my_table='users'; // Connecting, selecting database $link = mysql_connect($mysql_host,$mysql_user, $mysql_password) or die('Could not connect: ' . mysql_error()); mysql_select_db($my_database) or die('Could not select database'); // Performing SQL query $query = "SELECT user FROM $my_table"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); // Printing results in HTML //echo "<table>\n"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { //echo "\t<tr>\n"; foreach ($line as $col_value) { if ($col_value == $_REQUEST['username']) { $query = "SELECT pass FROM $my_table WHERE user=$col_value"; $result=mysql_query($query) or die('Query failed: ' . mysql_error()); echo $result; if ($result == $_REQUEST['password']) { echo "Welcome"; } else { echo "\nInvalid Password"; } } } } // echo "\t\t<td>$col_value</td>\n"; // } // echo "\t</tr>\n"; //} //echo "</table>\n"; // Free resultset mysql_free_result($result); // Closing connection mysql_close($link); ?> Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 change this $query = "SELECT pass FROM $my_table WHERE user=$col_value"; to $query = "SELECT pass FROM $my_table WHERE user='$col_value'"; Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted March 1, 2007 Share Posted March 1, 2007 also try $query = "SELECT pass FROM ".$my_table ".WHERE user='".$col_value."'"; good luck Quote Link to comment Share on other sites More sharing options...
newbienewbie Posted March 1, 2007 Author Share Posted March 1, 2007 itsmeArry, tried ur option, and received error Resource id #4 Invalid PasswordResource id #5 Invalid PasswordResource id #6 Invalid PasswordResource id #7 Invalid PasswordResource id #8 Invalid PasswordResource id #9 Invalid PasswordResource id #10 Invalid PasswordResource id #11 Invalid PasswordResource id #12 Invalid PasswordResource id #13 Invalid PasswordResource id #14 Invalid PasswordResource id #15 Invalid PasswordResource id #16 Invalid PasswordResource id #17 Invalid PasswordResource id #18 Invalid PasswordResource id #19 Invalid PasswordResource id #20 Invalid PasswordResource id #21 Invalid PasswordResource id #22 Invalid PasswordResource id #23 Invalid PasswordResource id #24 Invalid PasswordResource id #25 Invalid PasswordResource id #26 Invalid PasswordResource id #27 Invalid PasswordResource id #28 Invalid PasswordResource id #29 Invalid PasswordResource id #30 Invalid PasswordResource id #31 Invalid PasswordResource id #32 Invalid PasswordResource id #33 Invalid PasswordResource id #34 Invalid PasswordResource id #35 Invalid PasswordResource id #36 Invalid PasswordResource id #37 Invalid PasswordResource id #38 Invalid PasswordResource id #39 Invalid PasswordResource id #40 Invalid PasswordResource id #41 Invalid PasswordResource id #42 Invalid PasswordResource id #43 Invalid PasswordResource id #44 Invalid PasswordResource id #45 Invalid PasswordResource id #46 Invalid PasswordResource id #47 Invalid PasswordResource id #48 Invalid PasswordResource id #49 -------- PC Nerd, form disapared. nothing shown in browser. Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 Look wht you have here $result=mysql_query($query) or die('Query failed: ' . mysql_error()); echo $result; if ($result == $_REQUEST['password']) { echo "Welcome"; } else { echo "\nInvalid Password"; } usde this:: $result=mysql_query($query) or die('Query failed: ' . mysql_error()); while($row = mysql_fetch_array($result)) if ($row['password'] == $_REQUEST['password']) { echo "Welcome"; } else { echo "\nInvalid Password"; } Quote Link to comment Share on other sites More sharing options...
newbienewbie Posted March 2, 2007 Author Share Posted March 2, 2007 thanks it worked Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.