简体   繁体   English

Isset($ _ POST ['submit)不起作用

[英]Isset($_POST['submit) is not working

Isset($_POST['submit) is not working but when I add the not operation(!) it worked. Isset($ _ POST ['submit)不起作用,但是当我添加not操作(!)时它起作用了。 i don't where to find the error. 我不在哪里找到错误。 here is my code 这是我的代码

$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';
        }

    }

here is the submit form 这是提交表格

<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>

You are not submitting any values. 您没有提交任何值。

<input type="submit" name="submit">

Try something like this: 尝试这样的事情:

<input type="submit" name="submit" value="ok">

This piece of PHP checks if the form element with the name "submit" has any value: 这段PHP检查名称为“submit”的表单元素是否具有任何值:

"if isset($_POST['submit'])"

But since you haven't set any value for "submit", it won't validate. 但由于您没有为“提交”设置任何值,因此无法验证。 However, it will validate when you set the exclamation mark in front of it: 但是,它会在您设置前面的感叹号时进行验证:

!if isset($_POST['submit'])"

This is because then you are saying, "if 'submit' has no value set, do the following". 这是因为你说,“如果'提交'没有设置值,请执行以下操作”。

Hope that makes sense. 希望有道理。 :) :)

Update: You also have several other errors that you need to fix to get the whole thing working. 更新:您还需要修复其他几个错误才能使整个过程正常运行。 This should fix most of it. 这应该解决大部分问题。 Compare it to your current code: 将它与您当前的代码进行比较:

<?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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM