Dren Posted October 18, 2013 Share Posted October 18, 2013 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 ... Link to comment https://forums.phpfreaks.com/topic/283083-checking-if-email-is-already-used/ Share on other sites More sharing options...
BrodaNoel Posted October 18, 2013 Share Posted October 18, 2013 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 Link to comment https://forums.phpfreaks.com/topic/283083-checking-if-email-is-already-used/#findComment-1454433 Share on other sites More sharing options...
Dren Posted October 18, 2013 Author Share Posted October 18, 2013 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! Link to comment https://forums.phpfreaks.com/topic/283083-checking-if-email-is-already-used/#findComment-1454434 Share on other sites More sharing options...
BrodaNoel Posted October 18, 2013 Share Posted October 18, 2013 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 https://forums.phpfreaks.com/topic/283083-checking-if-email-is-already-used/#findComment-1454435 Share on other sites More sharing options...
Dren Posted October 18, 2013 Author Share Posted October 18, 2013 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 https://forums.phpfreaks.com/topic/283083-checking-if-email-is-already-used/#findComment-1454451 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.