Isset($ _ POST ['submit)无法正常工作,但是当我添加not操作(!)时,它工作正常。我不在哪里找到错误。 这是我的代码
$get = isset($_GET['id']) ? $_GET['id'] : "";
$query = "SELECT * FROM `crew_info` WHERE `id` = '$get'";
$query_run = mysqli_query($conn,$query);
if(!isset($_POST['submit'])) {
$query_update = "UPDATE `crew_info` SET `crew_status` = 'NEW' WHERE `id` = '$get'";
if ($query_update_run = mysqli_query($conn,$query_update)) {
echo 'Crew Accepted';
}
}
这是提交表单
<form action="review.php" method="POST">
<table border="2" align="center" width="600" cellspacing="3" cellpadding="4">
<tr>
<th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
<th>Date Added</th>
<th>Status</th>
</tr>
<tr>';
while($record = mysqli_fetch_assoc($query_run)) {
echo "<tr>";
echo "<th>".$record['first_name']."</th>";
echo "<th>".$record['middle_name']."</th>";
echo "<th>".$record['last_name']."</th>";
echo "<th>".$record['date_added']."</th>";
echo "<th>".$record['crew_status']."</th>";
echo '</tr>';
}
echo '</table>';
echo '<br><center><input type="submit" name="submit"></center>
</form>
答案 0 :(得分:0)
您没有提交任何值。
<input type="submit" name="submit">
尝试这样的事情:
<input type="submit" name="submit" value="ok">
这段PHP检查表单元素的名称是&#34;提交&#34;有任何价值:
"if isset($_POST['submit'])"
但是,由于您没有为&#34;提交&#34;设置任何值,因此无法验证。但是,它会在您设置前面的感叹号时进行验证:
!if isset($_POST['submit'])"
这是因为你说,&#34;如果&#39;提交&#39;没有设置值,请执行以下操作&#34;。
希望这是有道理的。 :)
更新:您还需要修复其他几个错误才能使整个过程正常运行。这应该解决大部分问题。将它与您当前的代码进行比较:
<?php $get = isset($_GET['id']) ? $_GET['id'] : "";
$query = "SELECT * FROM crew_info WHERE id = '$get'";
$query_run = mysqli_query($conn,$query);
if(isset($_POST['submit'])) {
$query_update = "UPDATE crew_info SET crew_status = 'NEW' WHERE id = '$get'";
if ($query_update_run = mysqli_query($conn,$query_update)) {
echo 'Crew Accepted';
}
} ?>
<form action="review.php" method="POST">
<table border="2" align="center" width="600" cellspacing="3" cellpadding="4">
<tr>
<th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
<th>Date Added</th>
<th>Status</th>
</tr>
<tr>
<?php
while($record = mysqli_fetch_assoc($query_run)) {
echo "<tr>";
echo "<th>".$record['first_name']."</th>";
echo "<th>".$record['middle_name']."</th>";
echo "<th>".$record['last_name']."</th>";
echo "<th>".$record['date_added']."</th>";
echo "<th>".$record['crew_status']."</th>";
echo '</tr>';
}
echo '</table>';
echo '<br><center><input type="submit" name="submit" value="ok"></center>';
?>
</form>