Jump to content

University exam exercise


Davecnll
 Share

Recommended Posts

Hi!! The day after tomorrow I've a HTML exam...

Would you mind help me with this exercise?? I couldn't find the way to do it looking to the tutorials.. but if there is, and I missed it, let me now!!

Create a HTML index.html containing a form:

  1. - with 2 text boxes to insert the name and the lastname;
    - a Submit button which sends the datas inserted by the user to a script php named namecontrol.php. 
  2. Create a PHP page which has to visualize the datas sent from the form, as a list.
Link to comment
Share on other sites

If it is just a singe first name, last name, just retrieve using $_GET or $_POST depending on whatever the method used in form, predefine html list, and echo out the result to that list.

IF more than one user, you would have to store users, add new user, the loop through these stored names producing individual list item elements with these first names and last names.

Link to comment
Share on other sites

So this is my answer for your problem:

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Name Control</title>
</head>
<body>
<form method="post" action="namecontrol.php" >
    <input type="text" name="name" placeholder="Insert your name ..." /><br/>
    <input type="text" name="lastname" placeholder="Insert your last name ..." /><br/>
    <input type="submit" value="Submit" name="submit" /><br/>
</form>
</body>
</html>

namecontrol.php (HTML LIST)

<?php

if($_SERVER['REQUEST_METHOD'] == "POST")
{
    if(isset($_POST['submit']))
    {
        $name = $_POST['name'];
        $lastName = $_POST['lastname'];

        if(empty($name) || empty($lastName))
        {
            echo "Please complete all fields to proceed !";
        }
        else
        {
            echo "<ul>";
            echo "<li>name: " . $name . " </li>";
            echo "<li>lastname: " . $lastName . "</li>";
            echo "</ul>";
        }
    }
}

?>

namecontrol.php (ARRAY)

<?php

if($_SERVER['REQUEST_METHOD'] == "POST")
{
    if(isset($_POST['submit']))
    {
        $name = $_POST['name'];
        $lastName = $_POST['lastname'];

        if(empty($name) || empty($lastName))
        {
            echo "Please complete all fields to proceed !";
        }
        else
        {
            $array = array("name" => $name, "lastname" => $lastName);
            print_r($array);
        }
    }
}

?>

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...