Jump to content

Checking if email is already used


Dren

Recommended Posts

Hi, i have a problem with my code...

I was dealing with registration and validation forms... and I encountered this problem.

When i enter an e-mail my code doesn't recognize it as already in use... and adds another user with the same email.
It doesn' say any error, just adds the new user with the same email in the table.

 

here my code:

	<?php
		include ("phpconnect.php");

		mysqli_select_db($connect, $database);
		echo "connected to $database<br>";

		$name = $_POST['user'];
		$surname = $_POST['surname'];
		$password = $_POST['password'];
		$email = $_POST['email'];
		$reemail = $_POST['email'];

		$check = mysqli_query($connect, "SELECT * FROM users WHERE email = '.$email.'");

		if(mysqli_num_rows($check) > 0){
			echo "The email is already in use!";
		}else{
			mysqli_query($connect, "INSERT INTO users (name, surname, password, email) VALUES ('$name', '$surname', '$password', '$email')");
			echo "added $email";

			mysqli_close($connect);
		}
	?>

I tried everything by looking on google ... 

Edited by Dren
Link to comment
Share on other sites

Change this line:

$check = mysqli_query($connect, "SELECT * FROM users WHERE email = '.$email.'");

for that:

$check = mysqli_query($connect, "SELECT * FROM users WHERE email = '$email'");

In the other hand, look, you have problems with security...

Please, read about: SQL Injection (search in google)

 

You need use this funcion: mysqli_real_escape_string().

Read about that quickly

Edited by BrodaNoel
Link to comment
Share on other sites

 

Change this line:

$check = mysqli_query($connect, "SELECT * FROM users WHERE email = '.$email.'");

for that:

$check = mysqli_query($connect, "SELECT * FROM users WHERE email = '$email'");

 

oh my ... ._." i tried the IMPOSSIBLE and the error was just that "."... thank you  :

It works now!

 

This code is just a game for me to learn better php... I'll write the security soon!

Edited by Dren
Link to comment
Share on other sites

The error is in SQL, not in PHP.

 

The QUERY executed are:

SELECT * FROM users WHERE email = '.BrodaNoel.'

And... .BrodaNoel. is not my username...

If you whant use "." the code should be:

$check = mysqli_query($connect, "SELECT * FROM users WHERE email = '".$email."'");
Link to comment
Share on other sites

 

The error is in SQL, not in PHP.

 

The QUERY executed are:

SELECT * FROM users WHERE email = '.BrodaNoel.'

And... .BrodaNoel. is not my username...

If you whant use "." the code should be:

$check = mysqli_query($connect, "SELECT * FROM users WHERE email = '".$email."'");

 

Oh thanks for your help :)

Link to comment
Share on other sites

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.