-1

I've been tearing my hair out trying to figure out why the isset($_POST['Submit']) is not executing with my form. The data from the form is just not passing into the php code. Basically the code does not seem to be recognizing something like $ffname = $_POST["ffname"];

<?php
$ffname = $flname = $femail = $fcemail = $fpass = $fcpass = "";
if(isset($_POST['ffname'])){
    $ffname = $_POST["ffname"];
    $flname = $_POST["flname"];
    $femail = $_POST["femail"];
    $fcemail = $_POST["fcemail"];
    $fpass = $_POST["fpass"];
    $fcpass = $_POST["fcpass"];
    echo "<p>Hello World<p>";
    $con = mysqli_connect("localhost", "root", "") or die(mysqli_error());
    mysqli_select_db($con, "userdata") or die(mysqli_error($con));
    mysqli_query($con,"INSERT INTO tbluser (fname, lname, email, pass) VALUES('$ffname', '$flname', '$femail', '$fpass')")
    or die (mysqli_error($con));
}

?>


<form method="post">
    First Name: <input type="text" name="ffname" id="ffname" value="<?php echo $ffname;?>"><br>
    Last Name: <input type="text" name="flname" value="<?php echo $flname;?>"><br>
    E-mail: <input type="email" name="femail" value="<?php echo $femail;?>"><br>
    Confirm E-mail: <input type="email" name="fcemail" value="<?php echo $fcemail;?>"><br>
    Password: <input type="password" name="fpass" value="<?php echo $fpass;?>"><br>
    Confirm Password: <input type="password" name="fcpass" value="<?php echo $fcpass;?>"><br>
    <input type="submit" name="Submit" value="submit">
</form>
Aire
  • 127
  • 2
  • 11
  • 3
    Name the submit: name='Submit' – Chris Mar 23 '16 at 13:21
  • 1
    Try and remove the space between ` – Epodax Mar 23 '16 at 13:28
  • What space? I tried removing the spaces between type, name .. but nothing happened. – Aire Mar 23 '16 at 13:31
  • If this is the latest version of your code, based on answers below, then you haven't done all of the things suggested. Please try all things suggested, and post THAT code that "doesn't work". (Removing form action, watch `$_POST['ffname']`. – random_user_name Mar 23 '16 at 13:46
  • Look at your browser's inspector tools' network tab and check out the details of the actual HTTP request that is being made. Are all the parameters posted as expected? Is the request redirected somehow? – deceze Mar 23 '16 at 13:47
  • @cale_b Okay, this is with everything you suggested. It does not work. – Aire Mar 23 '16 at 13:48
  • @deceze Well, the form data is correct. I'm not sure if that means anything. – Aire Mar 23 '16 at 13:51
  • I don't know. What *does* it mean? Did you have a look at your Web Inspector of choice? (Ctrl+Alt+C, or something similar, on Chrome, Safari and Firefox) – deceze Mar 23 '16 at 13:52
  • @deceze Yes, the network tab says it was a POST request with the correct form data. – Aire Mar 23 '16 at 13:54

3 Answers3

1

You need to give your input submit a name:

<input type="submit" name="Submit" value="Submit">
DerVO
  • 3,679
  • 1
  • 23
  • 27
1

You have pass name of element in $_POST

try put name attribute in input submit

<input type = "submit" name="Submit" value = "1">
JuniorNunes
  • 175
  • 1
  • 11
1

The other answer by @DerVO is correct. But there seems to be something else at play, since you say it still doesn't work.

A comment became too long, so I've built a full answer here.

Step 1:
Add a name to your input:

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

However, relying on the submit in your $_POST is not the best plan. So I suggest watching a different form field - for example, ffname:

Step 2:
Improve your watch, using a different field:

if ( isset( $_POST['ffname'] ) ) {
    // do your work
}

Lastly, you may be munging your form action attribute.

Step 3:
In order to keep things simple, if the form is supposed to submit to the same page, you can simply omit the form action.

<form method="post">

Betweeen these three items, the form will work, unless you have some problem with your server.

Step 4:

Clean up your form formatting. You've got odd spacing which is problematic. In an html element, the property="value" code needs to be without spaces, but spaces between properties. Example:

<!-- Your version -->
<input type = "text"name = "ffname"id = "ffname"value="<?php echo $ffname;?>"><br>
<!-- Clean / correct version -->
<input type="text" name="ffname" id="ffname" value="<?php echo $ffname;?>"><br>

Here's a "clean" version of your whole form:

<form method="post">
    First Name: <input type="text" name="ffname" id="ffname" value="<?php echo $ffname;?>"><br>
    Last Name: <input type="text" name="flname" value="<?php echo $flname;?>"><br>
    E-mail: <input type="email" name="femail" value="<?php echo $femail;?>"><br>
    Confirm E-mail: <input type="email" name="fcemail" value="<?php echo $fcemail;?>"><br>
    Password: <input type="password" name="fpass" value="<?php echo $fpass;?>"><br>
    Confirm Password: <input type="password" name="fcpass" value="<?php echo $fcpass;?>"><br>
    <input type="submit" name="Submit" value="submit">
</form>
random_user_name
  • 25,694
  • 7
  • 76
  • 115
  • Okay, I tried all three things. That must mean there is something wrong with my server? – Aire Mar 23 '16 at 13:42
  • Edit your question with the latest version of the code you are using, please. That's the ONLY way we can help, and be sure some other error isn't introduced. – random_user_name Mar 23 '16 at 13:43
  • Well that's just weird. What kind of computer are you using? What browser? – random_user_name Mar 23 '16 at 13:56
  • I am using a Macbook Pro with Bootcamp on Windows 10 and Google Chrome. I don't know if it helps but I'm also using PHP 7 with WAMP. Also using phpstorm to edit this. Also on university wifi, maybe something with that? – Aire Mar 23 '16 at 13:58
  • At this point, I'd recommend you review [this question](http://stackoverflow.com/q/1282909/870729), all the answers, **including reading the comments**. There's a variety of good stuff in there, and your code at this point should be working. – random_user_name Mar 23 '16 at 14:01
  • All right I took a look. Thanks for your help but I guess I will have to try this on another PC. – Aire Mar 23 '16 at 14:06
  • It seems it was a problem with my PC. I ran it on a different one and everything is working. – Aire Mar 23 '16 at 14:17