Jump to content

Return error in PHP when mysql duplicate entry is found


benoit1980

Recommended Posts

Hello all.

 

I have only started php a week ago and require your help as this problem is driving me crazy......

 

I have a form and the customers just enter their phone and email.

When a duplicate of any of them is found I wish to show the message "Your phone or Mobile is already registered"

 

Now when no duplication is found, I wish to echo something else.

 

I have done this code below but I cannot get it to work....I created the database, everything is going well in without problem when I remove the statement

<?php
if(mysql_affected_rows() == 0){    echo '<div align="center" class="text-not-correct">Your Phone Number or Email or both are already registered!</div>';?>   
 
Here is part of my code, I only need in this tiny area please.
 

<?php$link = mysqli_connect("localhost", $username, $password, $db_name)or die("cannot connect");  $mres_email = mysqli_real_escape_string($link, $_POST['email_form2']);$mres_phone = mysqli_real_escape_string($link, $_POST['phone_form2']);$mres_code = mysqli_real_escape_string($link, $_POST['code_form2']);       $query = "INSERT INTO $tbl_name VALUES (NULL, '$dat_date', '$mres_phone', '$mres_email', '$mres_code')";mysqli_query($link, $query);if(mysql_affected_rows() == 0){    echo '<div align="center" class="text-not-correct">Your Phone Number or Email or both are already registered!</div>';     mysqli_close($link); }else{header("Refresh: 5;url=http://pwebsite.com/vio/page1.php");echo '<div align="center" class="text-correct">Congratulation you are now registered!</div></br>';echo '<div align="center"><img src="loading.gif" width="100" height="100" /></div>';    ?>   
 
Remember, the script is working fine but not when I try to check for duplicate. please help :-))))
 
 
Thank you!
 
 
Benoit

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.