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
Edited by benoit1980
Link to comment
Share on other sites

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.