Phynix Phynix - 2 years ago 70
HTML Question

PHP/HTML: HTML File not Sending POST data to PHP file

I'm trying to create a login page, with a simple form consisting of a Username, Password and Submit Button. The data from the two textfields needs to be sent to the separate PHP file so that it can query my oracle database for their validity (this bit already works with dummy data).

I'm using POST on the form, but not only is the PHP file not receiving any data, when I use code I've found online to dump the contents of the POST, the HTML file isn't even generating any.

The HTML code is as follows:

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

<input type="text"

<input type="password"

<input type="submit"
value="LOG IN">


And the relevant PHP code I'm using to test the POST:

$username = htmlspecialchars($_POST['username']);
$password = htmlspecialchars($_POST['userpwd']);

$msg = "Username:" . $username . "\nPassword:" . $password;
echo nl2br($msg);

Nothing I've found anywhere has worked, so I'm coming here to (hopefully) find out its some silly mistake I've made and easily fixable. Cheers.

Answer Source

The error happens because you are using : instead of = after name

<input type="text" placeholder="Username:" name="username" required autofocus> 
<input type="password" placeholder="Password:" name="userpwd" required> 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download