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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站