• GoDaddy Community
  • GoCentral | Website Builder
  • GoCentral | Website Builder

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    $_POST not working, but $_GET is working. WHY?!

    I'm creating forms and have noticed that $_POST isn't working while $_GET works.  Here's the sample code, starting with $_POST that doesn't work:

    HTML FORM:

    <html>
    <body>

    <form action="welcome.php" method="post">
    Name: <input type="text" name="name"><br>
    E-mail: <input type="text" name="email"><br>
    <input type="submit">
    </form>

    </body>
    </html>

     

    PHP HANDLER:

    <html>
    <body>

    Welcome <?php echo $_POST["name"]; ?><br>
    Your email address is: <?php echo $_POST["email"]; ?>

    </body>
    </html>

     

    Now for the $_GET that is working (same exact code, just POST and GET are switched):

    HTML FORM:

    <html>
    <body>

    <form action="welcome_get.php" method="get">
    Name: <input type="text" name="name"><br>
    E-mail: <input type="text" name="email"><br>
    <input type="submit">
    </form>

    </body>
    </html>

     

    PHP HANDLER:

    <html>
    <body>

    Welcome <?php echo $_GET["name"]; ?><br>
    Your email address is: <?php echo $_GET["email"]; ?>

    </body>
    </html>

     

    Any ideas?  Is this a godaddy issue?

    7 REPLIES 7
    Anonymous
    Not applicable

    Re: $_POST not working, but $_GET is working. WHY?!

     


    @DST-Impact_Mgr wrote:

    I'm creating forms and have noticed that $_POST isn't working while $_GET works.  Here's the sample code, starting with $_POST that doesn't work:

    HTML FORM:

    <html>
    <body>

    <form action="welcome.php" method="post">
    Name: <input type="text" name="name"><br>
    E-mail: <input type="text" name="email"><br>
    <input type="submit">
    </form>

    </body>
    </html>

     

    PHP HANDLER:

    <html>
    <body>

    Welcome <?php echo $_POST["name"]; ?><br>
    Your email address is: <?php echo $_POST["email"]; ?>

    </body>
    </html>

     

    Now for the $_GET that is working (same exact code, just POST and GET are switched):

    HTML FORM:

    <html>
    <body>

    <form action="welcome_get.php" method="get">
    Name: <input type="text" name="name"><br>
    E-mail: <input type="text" name="email"><br>
    <input type="submit">
    </form>

    </body>
    </html>

     

    PHP HANDLER:

    <html>
    <body>

    Welcome <?php echo $_GET["name"]; ?><br>
    Your email address is: <?php echo $_GET["email"]; ?>

    </body>
    </html>

     

    Any ideas?  Is this a godaddy issue?


    Hi @DST-Impact_Mgr (some handle? lol)

     

    For starters:

    <form>
      E-mail:
      <input type="email" name="email"> (not text!)...
    </form>

     

    "I don't work here, just helping out when I can." Cat Very Happy

    Re: $_POST not working, but $_GET is working. WHY?!

    Thanks for the help.  That's not the issue, though.  $_POST doesn't work on godaddy server but it works on other servers.  Not sure why...

    Anonymous
    Not applicable

    Re: $_POST not working, but $_GET is working. WHY?!

    Hi @DST-Impact_Mgr,

     

    I too have had a ton of trouble with with PHP / forms and GD, lot's of pulling out of hair at first. I usually found it depended on the form layout or the problems were with gmail. 

    You will find though serious problems with your form as it is if used in production.

    1. Using text input instead of the correct 'email' can mean non email addresses can be added.
    2. Not using a maximum for inputs can lead to a lot of garbage.... like a name with 2,000 characters!
    3. Not using the strip_tags function can lead to users inserting malicious code (and another reason for correct input fields). Strip_tags function is used to strip any html or script tags........ so the code won't work.

    and that's just the start before sorting out why it's not working........

     

    "I don't work here, just helping out when I can." Cat Very Happy

    Anonymous
    Not applicable

    Re: $_POST not working, but $_GET is working. WHY?!

    Hi @DST-Impact_Mgr,

     

    Update @DST-Impact_Mgr,

     

    Built it on my site, wrote a very simple welcome.php page, works fine!! Nothing wrong with your code at all. (except those points above, but as a very simple form it works)

    This is just one reason I host my own site on my own server....... pulled enough hair out with GD servers, and that's just a truth................

     

    "I don't work here, just helping out when I can." Cat Very Happy

    Re: $_POST not working, but $_GET is working. WHY?!

    Thanks again for the help.  The original form was only used as an example.  I'll post below the actual form and php handler that I'm using, which works on other servers but not godaddy:

    HTML FORM:

     

    <!DOCTYPE html>
    <html>
    <head>
    <title>Add Team Member Form</title>
    </head>

    <body>

    <form method="POST" action="handler.php">
    <table>
    <tr><td>First Name:</td> <td><input type="text" name="firstname" required/></td></tr>
    <tr><td>Last Name:</td> <td><input type="text" name="lastname" required/></td></tr>
    <tr><td>Site ID:</td> <td><select name="siteID">
    <option value="San Jose">San Jose</option>
    <option value="Sunnyvale">Sunnyvale</option>
    <option value="Palo Alto">Palo Alto</option>
    </select> </td></tr>
    </table>
    <br />

    <input type="submit" name="singup" value="Enter Team Member">
    </form>

    </body>

    </html>

     

    PHP HANDLER:

     

    <?php
    $servername = "localhost";
    $username = "confidential";
    $password = "wouldn'tyouliketoknow";
    $dbname = "databasename";

    $firstname=$_POST["firstname"];
    $lastname=$_POST["lastname"];
    $siteID=$_POST["siteID"];

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    }

    $sql = "INSERT INTO TeamMembers (firstname, lastname, siteID)
    VALUES ('$firstname', '$lastname', '$siteID')";

    if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
    } else {
    echo "Error: " . $sql . "<br>" . $conn->error;
    }

    $conn->close();
    ?>

    This code works great on other servers, just not godaddy.  I'm wondering if it has to do with PHP's "register_globals"=OFF 

    I hope that supplying the actual code will help achieve an answer to this mystery.

    Anonymous
    Not applicable

    Re: $_POST not working, but $_GET is working. WHY?!

    Hi @DST-Impact_Mgr,

     

    No you have done the right thing, when testing you used a simplified form in order to isolate the problem down to the lowest denominator 'POST'.... and saw it wasn't working.

    Without going further into your code there I would just say that if the 'test' form won't work at the simplest level, neither will the more complicated. But register_globals should be off:

    http://php.net/manual/en/security.globals.php

    So no, it's not that.

     

    Have you spoken with support about this?

     

    edit: @DST-Impact_Mgr,

    There are quite a few sites where you can test your code, here is just one good one:

    https://www.codecademy.com/courses/testing-your-code/0/1

    Re: $_POST not working, but $_GET is working. WHY?!

    Haven't contacted support yet.  I've slimmed the issue down to $_POST passing blank values. Chat feature is down right now so I'll try support tomorrow.