Php 我的代码在数据库中有两个条目
我有一个代码将信息发送到数据库中的表中。代码如下:Php 我的代码在数据库中有两个条目,php,mysql,sql,function,Php,Mysql,Sql,Function,我有一个代码将信息发送到数据库中的表中。代码如下: <?php //session_start(); include("config.php"); $alertcityname = $_POST['city']; $alerareaname = $_POST['area']; $email = $_POST['emailid']; $phone = $_POST['phone']; $pref = $_POST['alert']; $insertQuery = "insert
<?php
//session_start();
include("config.php");
$alertcityname = $_POST['city'];
$alerareaname = $_POST['area'];
$email = $_POST['emailid'];
$phone = $_POST['phone'];
$pref = $_POST['alert'];
$insertQuery = "insert into fir_forward (username,town,area,email,phone,pref)
values ('".$_SESSION['username']."','".$alertcityname."','".$alerareaname."',
'".$email."','".$phone."','".$pref."')";
$msg = base64_encode("Registered Successfully");
mysql_query($insertQuery) or die("error in insert record");
if(mysql_query($insertQuery))
{
header("location:updatemess.php?msg=$msg");
}
else
{
header("location:noupdatemess.php?msg=Not Registered");
}
?>
F_id username townarea phone pref email
0000000001 0000000001 [->] 0000000009 [->] 0000725954499 sms hezragumbe@gmail.com
0000000002 0000000001 [->] 0000000009 [->] 0000725954499 sms hezragumbe@gmail.com
0000000003 0000000003 [->] 0000000002 [->] 0000734566778 email mildred.achieng@yahoo.ca
0000000004 0000000003 [->] 0000000002 [->] 0000734566778 email mildred.achieng@yahoo.ca
有人能帮忙让我看看错误吗。那是因为您运行了两次
mysql\u query()
。删除一个实例
//mysql_query($insertQuery) or die("error in insert record"); //<---- Comment this
if(mysql_query($insertQuery))
{
header("location:updatemess.php?msg=$msg");
}
else
//mysql\u查询($insertQuery)或die(“插入记录中的错误”)// 使用exit();插入数据之后
if(mysql_query($insertQuery))
{
header("location:updatemess.php?msg=$msg");
exit();
}
您也可以这样修改它,并检查是否设置了变量
if(isset($alertcityname ) && isset($alerareaname ) && isset($email ) && isset($alertcityname ) && isset($phone)&& isset($pref ) )
{
if(mysql_query($insertQuery))
{
header("location:updatemess.php?msg=$msg");
exit();
}
}
这个问题有趣的部分是,当我阅读这个问题时,我知道我必须查找两次函数:mysql\u query。想想看;)@Pakspul-Lolz。。很明显,我删除了Shankar建议的一个实例,效果很好