我是初学者。基本上我有一个具有正确名称设置的表单,它正确地将数据发送到MySQL表,但是每当我执行表单时它总是会插入额外的4个空白行/ ID。
以下是每次结果:http://i.stack.imgur.com/bnx5D.png
我不确定代码或设置本身是否有问题,有人可以帮忙吗?
PHP代码:
<?php
$email = $_POST['email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$member_company = $_POST['member_company'];
$member_address1 = $_POST['member_address1'];
$member_address2 = $_POST['member_address2'];
$member_city = $_POST['member_city'];
$member_country = $_POST['member_country'];
$member_post_code = $_POST['member_post_code'];
$member_phone = $_POST['member_phone'];
mysql_connect ("localhost", "username", "password") or die ('Error: ' . mysql_error());
mysql_select_db ("database");
$query="INSERT INTO Orders (ID, email, first_name, last_name, member_company, member_address1, member_address2, member_city, member_country, member_post_code, member_phone)
VALUES ('NULL', '".$email."', '".$first_name."', '".$last_name."', '".$member_company."', '".$member_address1."', '".$member_address2."', '".$member_city."', '".$member_country."', '".$member_post_code."', '".$member_phone."')";
mysql_query($query) or die ('Error updating database');
?>
答案 0 :(得分:1)
问题在于,每次执行请求时都会将数据保存在表格中。
您应该检查它是否是POST请求
if(isset($_POST){
//Then the form has been submitted
}
这也在每个GET请求上运行,这就是你得到那些空记录的原因。