问题是当我的脚本插入它重复数据时;比如在这张照片中它在数据库中添加了2次:
MySQL表:
页:
提交时,重定向到menu_submit
,插入完成后重定向到create_menu.php
这是menu_submit.php
<?php
include ("../include/layout/header.php");
include ("../include/check_connection.php");
include ("../include/check_page.php");
if(isset($_POST["submit"])) {
$menu_name = $_POST["menu"];
$optradio_choise = (int)$_POST["optradio"];
$rank_name = (int)$_POST["rank"];
$menu_name2 = mysqli_real_escape_String($conn,$menu_name);
$query = "
INSERT INTO `website_navbar` (
`item_name`,
`rank`,
`visible`
) VALUES (
'{$menu_name}',
'{$rank_name}',
{$optradio_choise}
)
";
$result = mysqli_query($conn, $query);
if(mysqli_query($conn, $query) && mysqli_affected_rows($conn)) {
echo "Menu add sucessfully";
redirect1("mange_content.php");
}
}
mysqli_close($conn);
?>
答案 0 :(得分:4)
mysqli_query
您是否发现了{{1}} 两次的电话?
答案 1 :(得分:0)
你写mysqli_query two times
这就是你的查询运行两次的原因insert two record
$result=mysqli_query($conn,$query);
if($result && mysqli_affected_rows($conn)){
echo "Menu add sucessfully";
redirect1("mange_content.php");
}
所以在$result
mysqli_query($conn,$query);
而不是if condition