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

报告相同问题?

悬赏问题

  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含