ngreenwood6 Posted August 1, 2008 Share Posted August 1, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/117657-solved-simple-php-question/ Share on other sites More sharing options...
ikmyer Posted August 1, 2008 Share Posted August 1, 2008 before doing the insert do a query on the database to see if the email is already in use... then based on the results from the query (if a record is found, mysql_num_rows()), do the insert. Quote Link to comment https://forums.phpfreaks.com/topic/117657-solved-simple-php-question/#findComment-605156 Share on other sites More sharing options...
.josh Posted August 1, 2008 Share Posted August 1, 2008 look up regex in the manual there are a million and one examples of specifically checking email and domain formats in the comments. Quote Link to comment https://forums.phpfreaks.com/topic/117657-solved-simple-php-question/#findComment-605157 Share on other sites More sharing options...
Andy-H Posted August 1, 2008 Share Posted August 1, 2008 <?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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/117657-solved-simple-php-question/#findComment-605160 Share on other sites More sharing options...
ngreenwood6 Posted August 1, 2008 Author Share Posted August 1, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/117657-solved-simple-php-question/#findComment-605188 Share on other sites More sharing options...
DarkWater Posted August 1, 2008 Share Posted August 1, 2008 You need to use the mysqli connection resource just like you would any other mysqli_query call. >_> Quote Link to comment https://forums.phpfreaks.com/topic/117657-solved-simple-php-question/#findComment-605190 Share on other sites More sharing options...
ngreenwood6 Posted August 1, 2008 Author Share Posted August 1, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/117657-solved-simple-php-question/#findComment-605191 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.