Jump to content

University exam exercise


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 post
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 post
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 post
Share on other sites

Seems wrong to ask for name then last name, name should represent full name, then you are asking for last name and repeating what you would have already provided.

Should Be First name/s or forename/s  and then last name in my opinion.

Edited by dsonesuk
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...