Jump to content

Recommended Posts

I am trying to enter some data into the database. I want it to check to make sure that the data is not already in the database. I want it to check to see if the email address is already in the database. If it is tell them it is and if its not send it through. Any help is appreciated.

 

Also, if anyone knows the solution to this that would be great too. I also want it to check that it is in the correct format (ex. [email protected]). If you can help please let me know.

Link to comment
https://forums.phpfreaks.com/topic/117657-solved-simple-php-question/
Share on other sites

<?php

if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
echo "The email you have entered is not a valid email format.";
}else{

code;

?>

 

$query_string = "SELECT id FROM tableName WHERE email = '$email' LIMIT 1";
$query = mysql_query($query_string)or die(mysql_error());
$num = mysql_numrows($query);

if ($num != 0){
echo "That email is in use by another account.";
}else{

code;

}

?>

I tried adding the second piece of your code to my script and I am getting this error:

 

Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\wamp\www\news\news.php on line 30

 

The lines look like this

 

$query_string = "SELECT email FROM users WHERE email = '$get_email' LIMIT 1";
$query = mysqli_query($query_string)or die(mysqli_error($mysql_connect));
$num = mysqli_num_rows($query);

 

any help is appreciated

I actually figured it out. In the code:

 

$query_string = "SELECT email FROM users WHERE email = '$get_email' LIMIT 1";
$query = mysqli_query([color=orange]$mysqli_connect,[/color]$query_string)or die(mysqli_error($mysqli_connect));
$num = mysqli_num_rows($query);

 

The orange text was not there so it was not connecting to the database

 

Thanks for the help though everyone.

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.