Jump to content

Entries posting twice to database and blank entries


deebler

Recommended Posts

Hi -

 

I'm having 2 issues with my mysql database.  One is that sometimes when someone submits the form it will post back to back to my table, it's not that the person submitted twice it's that it's duplicating the row a 2nd time.

 

Also I'm getting blank entires in my table as well, I don't understand this because you can't submit a blank form because I have certain fields required.

 

I have a line of code in there to prevent duplicates based on email or address, when i tested it it did not allow the duplicate entry, but I think it's still letting duplicates through.  I have seen quite a few over the past few days.

 

Here is my php code:

 

<?php


$con = mysql_connect(database login);
if (!$con)
{
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db(database);
//declare variables
$name = $_POST['name'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$cell = $_POST['cell'];
$email = $_POST['email'];
$keyword = $_POST['keyword'];
$kids = $_POST['kids'];
$visited = $_POST['visited'];
$info = $_POST['info'];
$result = mysql_query("SELECT * FROM database WHERE email = '$email' OR address = '$address'") or exit(mysql_error()); //check for duplicates
$num_rows = mysql_num_rows($result); //number of rows where duplicates exist
if($num_rows == 0) { //if there are no duplicates...insert

$sql="INSERT INTO database (id, name, address, city, state, zip, cell, email, keyword, kids, visited, info)
VALUES
('','$_POST[name]','$_POST[address]','$_POST[city]','$_POST[state]','$_POST[zip]','$_POST[cell]','$_POST[email]','$_POST[keyword]','$_POST[kids]','$_POST[visited]','$_POST[info]')"
;
if (!mysql_query($sql))  
  {  
  die('Error: ' . mysql_error());  
  }
}

mysql_close();

header ("Location: /common/contests/flaquarium/thankyou.html"); // Your code here to handle a successful verification            //};         

?>

 

THanks!

Link to comment
Share on other sites

which part of what I said do you not understand?

 

$sql="INSERT INTO database (id, name, address, city, state, zip, cell, email, keyword, kids, visited, info)
VALUES
('','$name','$address','$city','$state','$zip','$cell','$email','$keyword','$kids','$visited','$info')"

//use variables instead, this will allows you to sanitize the input before insertion as well

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.