Mike Maazallahi
Mike Maazallahi

Reputation: 1289

handling form using POST

I'm working on a form and form handler. Method is _POST and I handle it using PHP. Now , When I wanna Handle The Form , it said $username is undefined.

My Form :

<html>
  <head>
    <title>Register</title>
    <script type="text/javascript" src="includes/register_form_validator.js" ></script>
  </head>
  <body>
    <form method="post" action="includes/register_form_handler.php" name="register_form" >
      <label for="username" >Username :</label><input placeholder="username" type="text" /><br>
      <label for="password">Password :</label><input type="password" name="password" /><br>
      <label for="cpassword">Confirm Password :</label><input type="password" name="cpassword" /><br>
      <label for="email">E-Mail :</label><input type="email" name="email" onChange="" /><br>
      <input type="submit" value="Submit" />
    </form>
  </body>
</html>

handler :

<?php
// Do a Form Validation , Makes sure that resource is Valid///////////
$actual_link = "http://$_SERVER[HTTP_HOST]" . "/dcreview/register.php";
if (!isset($_SERVER['HTTP_REFERER'])) {
  echo "Invalid Form";
  exit;
} else {
  if ($_SERVER['HTTP_REFERER'] != $actual_link) {
    echo "Invalid Form";
    exit;
  }
}
///////////////////////////////////////////////////////////////////
// Processes Form //
$user = $_POST["username"];
$pass = $_POST['password'];
$email = $_POST['email'];

password_hash($pass, PASSWORD_BCRYPT);
?>

Upvotes: 0

Views: 64

Answers (2)

Cheesi
Cheesi

Reputation: 483

Your username doesn't have a name attribute. Use this:

<input name="username" placeholder="username" type="text" />

Upvotes: 3

Ravi Roshan
Ravi Roshan

Reputation: 570

Replace your Username HTML with this line

<label for="username" >Username :</label><input name="username" placeholder="username" type="text"  /><br>

Upvotes: 3

Related Questions