0

I have a database that has data written to it by 3 different forms. The good news is that the forms do write to the database. The bad news is that every time I hit the submit button on one of the forms, a duplicate entry gets created along with the first one.

The forms are online at http://digitaldemo.net/kickass/test.php It is not hooked up to a live database, but I wanted to get it online so that you can see the code.

Here is the add_player.php code that writes the form data to the database:

<?php

// contact to database
$connect = mysql_connect("localhost", "dariia", "celtic03") or die ("Error , check your server connection.");
mysql_select_db("football");

// Set up form variables //

//Get data in local variable
$Player=$_POST['Player'];
$Position=$_POST['Position'];
$Team=$_POST['Team'];

// check for null values
$query="INSERT INTO ff_projections(Player, Position, Team) VALUES('$Player','$Position','$Team')";
mysql_query($query)  or die(mysql_error());
echo "1 record has been entered.";

mysql_query($query) or die('Error, query failed');

?>
1
  • I think it is duplicating because you gave all your form elements the same name, so there is nothing wrong with PHP behavior, I think you need to rethink your forms structure. Commented May 18, 2012 at 1:34

1 Answer 1

5

You execute the query twice!!

mysql_query($query)  or die(mysql_error());

mysql_query($query) or die('Error, query failed');
Sign up to request clarification or add additional context in comments.

3 Comments

LOL oh my god. I have been coding WAY too many hours today. I feel like such a doofus.
That is so funny. I did something similar yesterday. Check out stackoverflow.com/questions/10630743/php-undefined-variable I really thought I was going crazy!! @user1255168
Funny how it happens like that sometimes. This is really my first foray into programming database functionality from the ground up. It's nerve wracking, but exhilarating too when things work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.