Jump to content

check existting user and password...


web_master

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/82846-check-existting-user-and-password/
Share on other sites

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';
}
?>

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

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.