Note that there are some explanatory texts on larger screens.

plurals
  1. POPrevent multiple data entries in MySQL
    primarykey
    data
    text
    <p>So here is the deal. I have looked around everywhere, and all other techniques relate to refreshing the browser, and methods to prevent the php page from resubmitting the post data. I am new to this (obviously :p) But anyways, my questions I believe is simple. I just want a method, possibly an if else statement that would check the post data entries, and if there is a match already in my table, than do not execute the query. I am not worried about querying all of the results of the table, as I only suspect this table will ever have 50-60 entries. </p> <p>Here is the php page that handles the form submission:</p> <pre>$firstName = $_POST['firstName']; $lastName = $_POST['lastName']; $email = $_POST['email']; $city = $_POST['city']; $state = $_POST['state']; $submitDate = date("Y-m-d"); mysql_connect ("localhost", "abc", "123") or die ('Error: ' . mysql_error()); mysql_select_db ("members"); $query = "INSERT INTO persons (ID, firstName, lastName, email, city, state, submitDate)VALUES ( 'NULL', '".$firstName."', '".$lastName."', '".$email."', '".$city."', '".$state."', '".$submitDate."' )"; mysql_query($query) or die ('Error Updating database'); echo "Database Updated With: " .$firstName ." " .$lastName ." " .$email ." " .$city ." " .$state; mysql_close($con); </pre> <p>Sorry, cant ever seem to get my php to format correctly with those code braces. Anyways. just to re-iterate, looking for a way to maybe based on the first and last name. if those already exist, then do not allow the submission of the data. I have tried a few if then statements but i do not think I am getting the concept down of comparing the result to my query. I hope this all makes sense!!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload