web_master Posted December 22, 2007 Share Posted December 22, 2007 Whats wrong here? please help! How can I check is exist the user or not... <?php session_start(); include("../mysql_connect.php"); error_reporting(E_ERROR); @ini_set('display_errors', '1'); //Query return from dbase $query_return = mysql_query("SELECT `ch_users_nick`, `ch_users_pass` FROM `ch_users` ORDER BY `ch_users_id`"); if(!$query_return) { print mysql_error(); exit; } while($request = mysql_fetch_array($query_return)) { $exist_nick = $request['ch_users_nick']; $exist_pass = $request['ch_users_pass']; } // If exist if($exist_nick == $_POST['ch_users_nick'] & $exist_pass == $_POST['ch_users_pass']) { //Update dBase $query_return = mysql_query("UPDATE `ch_users` SET `ch_user_session` = '".$_COOKIE['PHPSESSID']."' WHERE `ch_users_nick` = '".$_POST['ch_users_nick']."' AND `ch_users_pass` = '".$_POST['ch_users_pass']." "); if(!$query_return) { print mysql_error(); exit; ?> thnxs Quote Link to comment https://forums.phpfreaks.com/topic/82846-check-existting-user-and-password/ Share on other sites More sharing options...
corillo181 Posted December 22, 2007 Share Posted December 22, 2007 its very simple just do this <?php //get the nick $exist_nick = $request['ch_users_nick']; // do the query $query = "SELECT * FROM users WHERE nick=$exist_nick"; $result = mysql_query($query); //user num rows to count the rows found with that nick $rows = mysql_num_rows($result); // if the rows found are more than 0 than someone has it, other wise... if($rows>0){ echo 'someone has that nick'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/82846-check-existting-user-and-password/#findComment-421328 Share on other sites More sharing options...
revraz Posted December 22, 2007 Share Posted December 22, 2007 Assuming you have a form submitting the Username and PW $query = "SELECT * FROM ch_users WHERE ch_users_nick = '" .$_POST['uname'] . "' AND ch_users_pass = '" . $_POST['pword'] . "'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); //check rows if (mysql_num_rows($result) == 1) { //validated } else { //not validated } Quote Link to comment https://forums.phpfreaks.com/topic/82846-check-existting-user-and-password/#findComment-421330 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.