skip to Main Content

when i try to display summary of my html form inputs after cliquing on send button, the php code only work when I comment the if statement, and when not it execute else statement despite the form is completed.

here is my html code:

type<html lang="en">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="formulaire.php" method="post">
        <fieldset>
            <legend>Job search: complete the form</legend>
            <label>First name</label>
            <input type="text" name="coord[]" value="fname">
            <br>
            <br>
            <label>Last name</label>
            <input type="text" name="coord[]" value="lname">
            <br>
            <br>
            <label>Age</label>
            <input type="text" name="coord[]" value="age">
            <br>
            <br>
            <label>Spoken languages</label>
            <br>
            <br>
            <select name="languages[]" multiple="multiple">
                <option value="french">french</option>
                <option value="english">english</option>
                <option value="dutch">dutsh</option>
                <option value="spanish">spanish</option>
            </select>
            <br>
            <br>
            
            <label for="comp[]">XHTML</label>
            <input type="checkbox" name="comp[]" value="xhtml">
            <br>
            <label for="comp[]">pHp</label>
            <input type="checkbox" name="comp[]" value="php">
            <br>
            <label for="comp[]">MySql</label>
            <input type="checkbox" name="comp[]" value="mysql">
            <br>
            <label for="comp[]">ASP.net</label>
            <input type="checkbox" name="comp[]" value="asp.net">
            <br>
            <br>
            <input type="reset" value="reset">
            &nbsp;&nbsp;&nbsp;
            <input type="submit" value="Send">
        </fieldset>
    </form>
</body>
</html> here

here is my php code, when i comment "if", it works fine but when not, it execute else

<?php

if(isset($_POST["coord"]) && isset($_POST["languages"]) && isset($_Post["comp"])){
    echo"<table border="1"><tr><th>Récapitulatif de votre fiche d'information personnelle</th></tr><tr><td>";
    $fname=$_POST["coord"][0];
    $lname=$_POST["coord"][1];
    $age=$_POST["coord"][2];
    $language=$_POST["languages"];
    $competence=$_POST["comp"];
    echo"you are :&nbsp<b>$fname","&nbsp", "$lname","</b><br>you have:&nbsp<b> $age ans</b>";
    echo"<br>you can talk:";
    echo"<ul>";
    foreach ($language as $value) {
        echo"<li>$value</li>";}
        echo"</ul>";
    echo"you have the following skills:";
    echo"<ul>";
    foreach ($competence as $value) {
        echo"<li>$value</li>";}
        echo"</ul></td></tr>";

}


else{
    echo"<script type="text/javascript">";
    echo"alert('remplissez tous les chapms du formulaires!');";
    echo"window.history.back();";
    echo"</script>";

    }
?>

2

Answers


  1. In PHP variables are case sensitive.

    Replace isset($_Post["comp"]) with isset($_POST["comp"]) in your if

    Login or Signup to reply.
  2. I have caught a capitalization error with one of your variable names. $_POST must be capitalized because variables in PHP are case sensitive which means that $_Post["comp"] must be edited to $_POST["comp"] or your server will determine that this variable does not exist. You can beautify your PHP code and check for capitalization errors through https://beautifytools.com/php-beautifier.php if you encounter any further errors with your code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search