$_POST in php 5.3.5 does not work

后端 未结 9 1053
不思量自难忘°
不思量自难忘° 2021-01-07 02:17

I\'m working on a page in PHP 5.3.5, and it seems that $_POST doesn\'t contain the data submitted from my form.

This is the HTML file :

         


        
相关标签:
9条回答
  • 2021-01-07 02:52

    You have not POSTed, or something is clobbering $_POST.

    If you have no mention of $_POST in your code before trying to access them, then you haven't POSTed to your script.

    0 讨论(0)
  • 2021-01-07 02:54

    Here it worked, but in PHP 5.3.1. Try this:

    <!doctype html>
    <html>
    <head>
    <title>form</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
    
    <form method="post" action="process.php">
    <fieldset><legend>your data</legend>
    <input type="text" name="txtname" id="id_name" />
    <input type="text" name="txtage" id="id_age" />
    </fieldset>
    <button type="submit">OK</button>
    </form>
    
    </body>
    </html>
    
    
    <?php
    if(isset($_POST["txtname"]))
        $txtname = $_POST["txtname"];
    else
        unset($txtname);
    if(isset($_POST["txtage"]))
        $txtage = $_POST["txtage"];
    else
        unset($txtname);
    ?>
    <!doctype html>
    <html>
    <head>
    <title>form</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
    
    <p>Welcome <?=$txtname; ?>!<br />
    You are <?=$txtage; ?> years old.</p>
    </body>
    </html>
    
    0 讨论(0)
  • 2021-01-07 02:56

    Try to use capitals in POST:

    <form action="file.php" method="POST">
    

    Instead of:

    <form action="file.php" method="post">
    
    0 讨论(0)
  • 2021-01-07 03:01

    It's probably because you have magic_quotes_gpc turned on. You should turn it off: http://www.php.net/manual/en/security.magicquotes.disabling.php

    0 讨论(0)
  • 2021-01-07 03:05

    Try <?php var_dump($_POST); ?> to see what's really in there. There's no way $_POST is broken - it's gonna be something else. Possibly a server setting could be disabling $_POST.

    0 讨论(0)
  • 2021-01-07 03:10

    PHP 5.3 is moving away from using global, pre-set variables, like $_POST, to avoid vulnerabilities.

    The issue, as I understand it, is that programmers who have never had to use $_POST or $_GET might treat it as any other variable and open themselves up to security threats.

    I haven't discovered the "proper" way to retrieve $_POST data yet, but the method I've using seems fairly sanitary.

    <?php parse_url(file_get_contents("php://input"), $_POST); 
    

    This transfers the parsed HTTP POST string to the $_POST variables

    0 讨论(0)
提交回复
热议问题