我的网页与更新语句有数据库连接。我有submit button
,点击按钮,数据库需要更新。但是在访问特定页面或刷新页面时,它会自动更新数据库。我没有设置任何功能或其他任何功能。
这是php代码:
<?php
$connect=mysqli_connect('127.0.0.1', 'root', 'root',"web");
if (isset($_GET['submit'])){
$query = "UPDATE student AS t1
INNER JOIN employer AS t2 ON t1.stud_location = t2.emp_location
SET t1.emp_id = t2.emp_id";
$search_result =mysqli_query($connect,$query);
} else {
$query = "UPDATE student AS t1
INNER JOIN employer AS t2 ON t1.stud_location = t2.emp_location
SET t1.emp_id = t2.emp_id";
$search_result =mysqli_query($connect,$query);
}
?>
答案 0 :(得分:0)
您声明您只想在提交表单时更新,如果是这样,您最好的选择是使用$ _POST而不是$ _GET。此外,您告诉您的页面,如果$ _GET ['submit']存在,则执行此操作,否则运行此操作(这与它确实存在时相同。)您应该阅读PHP dealing with Forms 如果您希望查询仅在表单已提交时运行,则应具有以下内容:
<?php
$connect=mysqli_connect('127.0.0.1', 'root', 'root',"web");
if (isset($_POST['submit'])){
$query = "UPDATE student AS t1 INNER JOIN employer AS t2 ON t1.stud_location = t2.emp_location SET t1.emp_id = t2.emp_id";
$search_result =mysqli_query($connect,$query);
}
?>