php basic code for user name and selected color show to the other page

technical talkiess
0

php basic code for user name and selected color show to the other page 

colors.php

<!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Faviourite color With name</title>
</head>
<body>
    <div class="container">
        <form action="color.php" method="post">
            <label for="name">Enter your name please</label>
            <input type="text" name="name" id="name">
            <label for="color">Choose your  Faviourite color.</label>
           <label for="red">Red</label> <input type="checkbox" name="color[]" value="red">
           <label for="Yellow">yellow</label> <input type="checkbox" name="color[]" value="yellow">
           <label for="green">green</label> <input type="checkbox" name="color[]" value="green">
           <label for="blue">blue</label> <input type="checkbox" name="color[]" value="blue">
           <label for="purple">purple</label> <input type="checkbox" name="color[]" value="purple">
            <input type="submit" value="Submit">
        </form>
    </div>
</body>
</html>


color.php

<?php
// var_dump($_POST);
if(!empty($_POST)){

    $name = $_POST['name'];
    $color = $_POST['color'];

    echo "Your name Is - " . $name . " <br>";

    echo "Choose color is - ";
    echo '<select name="color" id="color">';
    foreach ($color as $key => $value) {
       ?>
   
        <option value="<?php echo $value; ?>" name="color"><?php echo $value; ?></option>
   

<?php

    }
    echo "</select>";
}


?>


Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)