colleyboy Posted June 8, 2012 Share Posted June 8, 2012 Hello I am having a little problem whilst coding a login system I have done the "login part" but when it gets to the user_cp page I need to display the "user_id" field on the row where the "username" and "password" are a match. <?php include "dbconnect.php" ?> <p>USER CP</p> <p><A HREF="logout.php">LOGOUT</A></p> <?php if (isset($_GET['username'])) { $username = $_GET['username']; } if (isset($_GET['sessionid'])) { $password = $_GET['sessionid']; } ?> <?php $usersession = mysql_query("SELECT Username, Password FROM boom_users WHERE Username=$username && Password=$password") or die(mysql_error()); while($row = mysql_fetch_array($usersession)) { echo $row['user_id']; } echo $username; echo $password; ?> BTW the username and password are displayed in the URL under "username" and "session_id". I have echoed these to see if they display on page and they do. The password is encrypted to not a problem. I think the problem is in the part of: "$usersession = mysql_query("SELECT Username, Password FROM boom_users WHERE Username=$username && Password=$password") or die(mysql_error()); while($row = mysql_fetch_array($usersession))" It seems to check the table for a column which is the $username and $password from the url and what it should do check the table for where there is a match for username and password and then fetch the data in the column "user_id". Your help is much appreciated and I am sure it is an easy fix as I have been behind the computer around 10 hours today lol . Kind Regards, Ian Quote Link to comment https://forums.phpfreaks.com/topic/263885-mysql-and-php-problem-selecting-a-row-where-username-and-password-match/ Share on other sites More sharing options...
Pikachu2000 Posted June 8, 2012 Share Posted June 8, 2012 When posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/263885-mysql-and-php-problem-selecting-a-row-where-username-and-password-match/#findComment-1352304 Share on other sites More sharing options...
Barand Posted June 8, 2012 Share Posted June 8, 2012 put string values in single quotes SELECT Username, Password FROM boom_users WHERE Username='$username' && Password='$password' Quote Link to comment https://forums.phpfreaks.com/topic/263885-mysql-and-php-problem-selecting-a-row-where-username-and-password-match/#findComment-1352305 Share on other sites More sharing options...
Pikachu2000 Posted June 8, 2012 Share Posted June 8, 2012 As for your issue, aside from what Barand said, you aren't selecting the user_id field in the query, which means it won't be present in the results set . . . Quote Link to comment https://forums.phpfreaks.com/topic/263885-mysql-and-php-problem-selecting-a-row-where-username-and-password-match/#findComment-1352306 Share on other sites More sharing options...
colleyboy Posted June 8, 2012 Author Share Posted June 8, 2012 Single quotes Silly me! And sorry for not putting code in the script tags... will do next time... consider me told Once again... many thanks! Ian Quote Link to comment https://forums.phpfreaks.com/topic/263885-mysql-and-php-problem-selecting-a-row-where-username-and-password-match/#findComment-1352309 Share on other sites More sharing options...
jestino.engg23 Posted June 9, 2012 Share Posted June 9, 2012 Dear friends, i need a code to validate username & password saved in database without using sessions..... Can any1 plz provide me the code... Thnks in advance... Quote Link to comment https://forums.phpfreaks.com/topic/263885-mysql-and-php-problem-selecting-a-row-where-username-and-password-match/#findComment-1352424 Share on other sites More sharing options...
Barand Posted June 9, 2012 Share Posted June 9, 2012 1) try reading this thread as an example 2) do not hijack other people's threads, start your own Quote Link to comment https://forums.phpfreaks.com/topic/263885-mysql-and-php-problem-selecting-a-row-where-username-and-password-match/#findComment-1352425 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.