简体   繁体   中英

nothing happens when clicking on my submit button no _POST values

For some reason nothing happens when a user click on my submit button. The html look like this:

<td colspan="3">
          <div align="center">
            <input name="Decline" id="Decline" value="Decline" type="submit">
            |
            <input name="Accept" value="Accept" type="submit">
          </div><input name="place" value="user1" type="hidden"><input name="id" value="1" type="hidden">
</td>

I use php to get this html code from my database. It's part of an message system on my site where users can send messages to other users and accept and decline the request from other users. I get the message from the db like this:

while($get = mysql_fetch_object($mysql1)){
                echo $get->message;

When I try to use this information $_POST shows nothing.

I tested that with this code:

            if (!empty($_POST)){
            echo "test"; // nothing shows up!
            }

You need to wrap you input fields in a FORM tag. Try:

<td colspan="3">
      <div align="center">
        <form method="post" action="/path/to/script.php">
        <input name="Decline" id="Decline" value="Decline" type="submit">
        |
        <input name="Accept" value="Accept" type="submit">
      </div><input name="place" value="user1" type="hidden"><input name="id" value="1" type="hidden">
      </form>
</td>

Make sure that:

  • You have form tag there
  • And it is set to POST method
  • Check with var_dump($_POST);

Turn on error checking to see any possible errors:

ini_set('display_errors', true);
error_reporting(E_ALL);

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