1

This should be printed on output browser side:

$form = <<<EOT
<form action="register.php" method="POST">
First Name: <input type="text" name="name" /></br>
Last Name: <input type="text" name="lname" /></br>
Username: <input type="text" name="uname" /></br>
Email: <input type="text" name="email1" /></br>
Confirm Email: <input type="text" name="email2" /></br>
Password: <input type="password" name="pass1" /></br>
Confirm Password: <input type="password" name="pass2" /></br>
<input type="submit" value="Register" name="submit" />
</form>
EOT;
echo $form;

But there is nothing.

This is my full code, which I should have added in the first place.

<?php
    require("config.php");
?>
<?php
if(isset($_POST['submit'])){

    $email1 = $_POST['email1'];
    $email2 = $_POST['email2'];
    $pass1 = $_POST['pass1'];
    $pass2 = $_POST['pass2'];

    if($email1 == $email2) {
        if($pass1 == $pass2) {
    //All good. Nastavi broo.

        $name = mysql_escape_string($_POST['name']);
        $lname = mysql_escape_string($_POST['lname']);
        $uname = mysql_escape_string($_POST['uname']);
        $email1 = mysql_escape_string($email1);
        $email2 = mysql_escape_string($email2);
        $pass1 = mysql_escape_string($pass1);
        $pass2 = mysql_escape_string($pass2);

    }else{
      echo "Sorry, your password is not corrext.";
      exit();
    }
}else{
  echo "Sorry!";
}

$form = <<<EOT
<form action="register.php" method="POST">
First Name: <input type="text" name="name" /></br>
Last Name: <input type="text" name="lname" /></br>
Username: <input type="text" name="uname" /></br>
Email: <input type="text" name="email1" /></br>
Confirm Email: <input type="text" name="email2" /></br>
Password: <input type="password" name="pass1" /></br>
Confirm Password: <input type="password" name="pass2" /></br>
<input type="submit" value="Register" name="submit" />
</form>
EOT;
echo $form;

}
?>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Amar Muratović
  • 451
  • 2
  • 5
  • 11

1 Answers1

0

Your form will only appear once you click the submit button because it is set inside the if(isset($_POST['submit'])){...} conditional statement. Therefore, you need to move your last brace } above $form = <<<EOT.

} // it belongs here instead of below echo $form;
$form = <<<EOT
<form action="register.php" method="POST">
First Name: <input type="text" name="name" /></br>
Last Name: <input type="text" name="lname" /></br>
Username: <input type="text" name="uname" /></br>
Email: <input type="text" name="email1" /></br>
Confirm Email: <input type="text" name="email2" /></br>
Password: <input type="password" name="pass1" /></br>
Confirm Password: <input type="password" name="pass2" /></br>
<input type="submit" value="Register" name="submit" />
</form>
EOT;

echo $form;

?>

and make sure you are accessing it as http://localhost/file.php and not as c://file.php


EDIT:

Here's a rewrite:

<?php
require("config.php");
?>
<?php
if(isset($_POST['submit'])){

$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];

if($email1 == $email2) {
    if($pass1 == $pass2) {
//All good. Nastavi broo.

$name = mysql_escape_string($_POST['name']);
$lname = mysql_escape_string($_POST['lname']);
$uname = mysql_escape_string($_POST['uname']);
$email1 = mysql_escape_string($email1);
$email2 = mysql_escape_string($email2);
$pass1 = mysql_escape_string($pass1);
$pass2 = mysql_escape_string($pass2);


}else{
  echo "Sorry, your password is not corrext.";
  exit();
}
}else{
  echo "Sorry!";
}

} // brace for submit conditional

$form = <<<EOT
<form action="register.php" method="POST">
First Name: <input type="text" name="name" /></br>
Last Name: <input type="text" name="lname" /></br>
Username: <input type="text" name="uname" /></br>
Email: <input type="text" name="email1" /></br>
Confirm Email: <input type="text" name="email2" /></br>
Password: <input type="password" name="pass1" /></br>
Confirm Password: <input type="password" name="pass2" /></br>
<input type="submit" value="Register" name="submit" />
</form>
EOT;
echo $form;

?>

Passwords

I also noticed that you may be storing passwords in plain text. This is not recommended. If you intend on going LIVE with this, do read the following.

Use one of the following:

Other links:

Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141