dongzhen7108 2012-05-18 01:30
浏览 35
已采纳

PHP表单向MySQL数据库提交重复的条目

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条回答 默认 最新

  • dqtl46964 2012-05-18 01:33
    关注

    You execute the query twice!!

    mysql_query($query)  or die(mysql_error());
    
    mysql_query($query) or die('Error, query failed');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 Python如何后台操作Vmwake虚拟机键鼠
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容