Jump to content

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

}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.