简体   繁体   中英

Isset($_POST['submit) is not working

Isset($_POST['submit) is not working but when I add the not operation(!) it worked. 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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