Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,043 members, 7,818,091 topics. Date: Sunday, 05 May 2024 at 07:31 AM

Checking User And Email Already Exist - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Checking User And Email Already Exist (522 Views)

I Will Extract Phone Number And Email Of Any Facebook Page Or Group For You / If Already Exist PHP / Content Blogpost And Email Writer Needed (2) (3) (4)

(1) (Reply) (Go Down)

Checking User And Email Already Exist by freelancenig: 2:19pm On May 07, 2017
Help sort out this code

if(isset($_POST) & !empty($_POST)){
$fname = mysqli_real_escape_string($con, $_POST['fname']);
$sname = mysqli_real_escape_string($con, $_POST['sname']);
$password = mysqli_real_escape_string($con, hash("sha256", ($_POST['password'])));
$email = mysqli_real_escape_string($con, $_POST['email']);

$check_user = "SELECT count(*) FROM table WHERE username='$fname'";
$check_user_result = mysqli_query($con, $check_user);


if($check_user_result > 0){
$notEmpty = "User exist, please try another username";
}else{

$data_insert = "INSERT INTO crud (first_name, last_name, password, email_id) VALUES('$fname', '$sname', '$password', '$email')";

$data_query = mysqli_query($con, $data_insert) or die(mysqli_error($con));

if($data_query){
$smsg = "Data successfully inserted";
}else{
$fmsg = "Data insertion not successful, try again";
}

}
}

?>
Re: Checking User And Email Already Exist by Lantean(m): 5:57pm On May 07, 2017
freelancenig:
Help sort out this code


Hello freelancenig.
You didn't tell what you have as the error message coupled with what you want to accomplish.

However:
$check_user should be $fname NOT '$fname'. The latter is a literal string rather than a variable which you intend for the spot.
In $data_insert, you did the same to the post variables. E.g. $fname NOT '$fname'. Do same correction for the other variables.
Re: Checking User And Email Already Exist by mcqwerty(m): 8:55pm On May 08, 2017
Don't hash the password in the password variable. Do that at the point of insertion onto the database.

//Check for existing username:

$query= "SELECT * FROM users WHERE username='$username'";
$data=mysqli_query($conn, $query);
//not found, then insert
if (mysqli_num_rows($data) == 0){
$query="INSERT into users (username, password) VALUES ('$username', SHA256('$password') )";
mysqli_query($conn, $query);
echo 'Success';
}else{
echo 'user exists!'
}

Just follow this sort of logic
Re: Checking User And Email Already Exist by Greene66: 9:05am On May 09, 2017
Wrong.

Hash the password BEFORE the query in a variable such as

$password = hash ('sha256', $pass);

And you should use mysqli_num_rows ();

To check that it exists, it should be >0 not ==0
To check that it DOES NOT exists, it should be <1
Re: Checking User And Email Already Exist by mcqwerty(m): 8:37pm On May 09, 2017
Greene66:
Wrong.

Hash the password BEFORE the query in a variable such as

$password = hash ('sha256', $pass);

And you should use mysqli_num_rows ();

To check that it exists, it should be >0 not ==0
To check that it DOES NOT exists, it should be <1

Your coding logic is so wrong.
if $username shouldnt exist then mysqli_num_rows == 0 and not > 0

(1) (Reply)

NĂ«ed A Good Bulk SMS With Android App / 1k - 2k Followers Facebook, Twitter, Instagram Pages Needed ... / How To Start A Hosting Company

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 16
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.