Jump to content

[SOLVED] Simple php question


ngreenwood6

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.

Archived

This topic is now archived and is closed to further replies.

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