TedCopple Posted February 18, 2011 Share Posted February 18, 2011 Alright, wasn't quite sure how to summarize this in the title, but I want to: Check if a user status is "active" or not based on the UserName input. I have a table witch holds: VarChar Username Var CharPassWord int Active Ted TedsPW 1 something like the above(assuming it formatted correctly. In my php script I will want to input a variable for Username to check for: inputUN in this example would be "Ted". $UserNameToCheck = $_GET['inputUN']; Then I want to check for that UserName in the database, if it exists, I want pull the value for the "Active" field for just that UserName and echo it. Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/228132-reading-mysql-row-check-entry-in-row-and-get-another-entryconfusing-title/ Share on other sites More sharing options...
Psycho Posted February 18, 2011 Share Posted February 18, 2011 //Clean input and prevent sql injection attack $UserNameToCheck = mysql_real_escape_string(trim($_GET['inputUN'])); $query = "SELECT active FROM tableName WHERE Username = '{$UserNameToCheck}'"; $result = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result)==0) { echo "The user {$UserNameToCheck} does not exist."; } else { $activeStatus = (mysql_result($result, 0)=='1') ? 'active' : 'not active'; echo "The user {$UserNameToCheck} is {$activeStatus}"; } Quote Link to comment https://forums.phpfreaks.com/topic/228132-reading-mysql-row-check-entry-in-row-and-get-another-entryconfusing-title/#findComment-1176443 Share on other sites More sharing options...
Maq Posted February 18, 2011 Share Posted February 18, 2011 - Query the database: SELECT Active FROM [table] WHERE Username = '$UserNameToCheck'; - Use mysql_num_rows to check if there are results. - There are examples of how to do this in the manual link above. Quote Link to comment https://forums.phpfreaks.com/topic/228132-reading-mysql-row-check-entry-in-row-and-get-another-entryconfusing-title/#findComment-1176446 Share on other sites More sharing options...
TedCopple Posted February 18, 2011 Author Share Posted February 18, 2011 Alright thanks to the both of you for responses. Very helpful stuff. Also thanks for the little bit of SQL Injection prevention. Somebody mentioned something about that to me earlier today, and I was going to look into it, so thanks. Quote Link to comment https://forums.phpfreaks.com/topic/228132-reading-mysql-row-check-entry-in-row-and-get-another-entryconfusing-title/#findComment-1176456 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.