1

I'm new to PHP and I have a problem about my Javascript is not working for now.

Here is my codes so far

    <?php

        $email = $_POST["App_Email"];
        $password = $_POST["App_Password"];
        $name = $_POST["App_Name"];
        $lName = $_POST["App_LName"];
        $gender = $_POST["App_Gender"];
        $birthday = $_POST["App_Birthday"];
        $nationality = $_POST["App_Nationality"];
        $telNumber = $_POST["App_Tel"];
        $address = $_POST["App_Address"];
        $district = $_POST["App_District"];
        $city = $_POST["App_City"];
        $zipcode = $_POST["App_Zipcode"];

        $repass = $_POST["RePassword"];

        $message = "";
        if($email == ""  or $password == "" or $repass == "" or $name == "" or $lName == "" or $birthday == "" or $nationality == "" or $telNumber == "" or $address == "" or $district == "" or $city == "" or $zipcode == "" ){
            $message = "FILL ALL";
        }
        elseif($repass != $password){
            $message = "NOT MATCH"; 
        }

    echo '<script type="text/javascript">';


    if($message == "FILL ALL"){
        echo 'alert("Please fill in all provided field(s).")';
        echo 'location.href = "registration.php"';
        return;
    }
    else if($message == "NOT MATCH"){
        echo 'alert("Your confirmation password is not match with your password.")';
        echo 'location.href = "registration.php"';
        return;
    }


echo '</script>';

?>

<br><br>

<form method="POST" action="confirm-registration.php">

Name : <?php echo $_POST["App_Name"]; ?><br><br>
Lastname : <?php echo $_POST["App_LName"]; ?><br><br>
Gender :  <?php echo $_POST["App_Gender"]; ?><br><br>
Date of birth : <?php echo $_POST["App_Birthday"]; ?> <br><br>
Nationality : <?php echo $_POST["App_Nationality"]; ?><br><br>
Tel. : <?php echo $_POST["App_Tel"]; ?><br><br>
Address : <?php echo $_POST["App_Address"]; ?><br><br>
District : <?php echo $_POST["App_District"]; ?><br><br>
City : <?php echo $_POST["App_City"]; ?><br><br>
Zipcode : <?php echo $_POST["App_Zipcode"]; ?><br><br>

<input type='hidden' name='App_Email' value='<?=$email?>'>
<input type='hidden' name='App_Password' value='<?=$password?>'>
<input type='hidden' name='App_Name' value='<?=$name?>'>
<input type='hidden' name='App_LName' value='<?=$lName?>'>
<input type='hidden' name='App_Gender' value='<?=$gender?>'>
<input type='hidden' name='App_Birthday' value='<?=$birthday?>'>
<input type='hidden' name='App_Nationality' value='<?=$nationality?>'>
<input type='hidden' name='App_Tel' value='<?=$telNumber?>'>
<input type='hidden' name='App_Address' value='<?=$address?>'>
<input type='hidden' name='App_District' value='<?=$district?>'>
<input type='hidden' name='App_City' value='<?=$city?>'>
<input type='hidden' name='App_Zipcode' value='<?=$zipcode?>'>

<button onClick="history.back()";> Back </button>  <input type="submit" name="submit" value="Confirm">
</form>

From the codes above, my result in this page is just a plain white page.

When I tried to test the not completed the form case and password is not matched. But no alert is pop-up. Even all fields from the form page is inserted, this page stills plain white.

Please help.

2
  • 5
    Why return in if? Commented May 27, 2016 at 8:32
  • You know the purpose of return, don't you? Commented May 27, 2016 at 8:34

2 Answers 2

3

Various problems in your code:

  1. Missing isset(). Turn on your error reporting, you will find numerous Notice: Undefined index errors
  2. Why return in if? Is it a function?
  3. Missing ; in your Javascript:

    if($message == "FILL ALL"){
        echo 'alert("Please fill in all provided field(s).");';
        echo 'location.href = "registration.php";';
    
    }
    else if($message == "NOT MATCH"){
        echo 'alert("Your confirmation password is not match with your password.");';
        echo 'location.href = "registration.php";';
    }
    
  4. All your HTML fields are hidden, where does the user enter values?

Sign up to request clarification or add additional context in comments.

1 Comment

for (4) it is from the last page. i didn't post my codes
0

Use ; inside echo statements

if($message == "FILL ALL"){
  echo 'alert("Please fill in all provided field(s).");';
  echo 'location.href = "registration.php";';
}
else if($message == "NOT MATCH"){
   echo 'alert("Your confirmation password is not match with your password.");';
   echo 'location.href = "registration.php";';
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.