我尝试将数组插入数据库。它确实插入,但只有admin = 0&& special admin!= 1.当我尝试更改数据库时,我将admin设置为3,特殊管理员设置为!= 1,它根本不会插入。
这里需要帮助,所以这是我到目前为止的代码
$ques = "SELECT * FROM ip_restriction where ipnum = '".$ip_2."'";
$ress = mysql_query($ques);
if ($roww = mysql_fetch_array($ress)) {
if ($row ['admin'] == 0 && $row['special_admin']!=1)
{
$queinsert = "INSERT INTO tblid (ipadd, ipdept, createdby, datecreated)
VALUES ('".$ip_2."', 'AGENT', 'Admin', NOW())";
}
elseif ($row ['admin'] == 0 && $row['special_admin']==1 )
{
$queinsert = "INSERT INTO tblid (ipadd, ipdept, createdby, datecreated)
VALUES ('".$ip_2."', 'AGENT', 'Admin', NOW())";
}
elseif ($row ['admin'] == 3 && $row['special_admin']!=1 )
{
$queinsert = "INSERT INTO tblid (ipadd, ipdept, createdby, datecreated)
VALUES ('".$ip_2."', 'CLIENT', 'Admin', NOW())";
}
elseif ($row ['admin'] == 3 && $row['special_admin']==1 )
{
$queinsert = "INSERT INTO tblid (ipadd, ipdept, createdby, datecreated)
VALUES ('".$ip_2."', 'CLIENT', 'Admin', NOW())";
}
elseif ($row ['admin'] == 4 && $row['special_admin']!=1 )
{
$queinsert = "INSERT INTO tblid (ipadd, ipdept, createdby, datecreated)
VALUES ('".$ip_2."', 'AGENT', 'Admin', NOW())";
}
$ressinput= mysql_query($queinsert);
header('Location: index.php');
}
答案 0 :(得分:1)
你可以试试这个。 bcoz无论条件是什么,你在DB中插入相同的值。所以我不明白放条件的实际意义。
$ques = "SELECT * FROM ip_restriction where ipnum = '".$ip_2."'";
$ress = mysql_query($ques);
if ($roww = mysql_fetch_array($ress))
{
$queinsert = "INSERT INTO tblid (ipadd, ipdept, createdby, datecreated)
VALUES ('".$ip_2."', 'AGENT', 'Admin', NOW())";
}
$ressinput= mysql_query($queinsert);
header('Location: index.php');
答案 1 :(得分:0)
尝试:
$ressinput = mysql_query($queinsert);
if (!$ressinput) {
die('Invalid query: ' . mysql_error());
} else {
header('Location: index.php');
}