settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Create HTML Form with PHP and print (show) "Hello, Person!"

+3 votes

I need to create one HTML form for data submission + print "Hello, Person!"

The person MUST be from the user's input!

asked in PHP category by user hues

2 Answers

+2 votes
 
Best answer

Here's the solution: note line #8 - because you always MUST use htmlspecialchars for checking users' input!

 

<!DOCTYPE html>
<html>
<head>
    <title>Input Form</title>
</head>
<body>
<?php if (isset($_GET['person'])) {
    $person = htmlspecialchars($_GET['person']);
    echo "Hello, $person!";
} else {
    ?>
    <form>
        Name: <input type="text" name="person"/><br>
        <input type="submit">

    </form>
<?php } ?>
</body>
</html>

 

answered by user icabe
selected by user golearnweb
+1 vote

You can also see my solution:

<!DOCTYPE html>
<html>
<head>
    <title>Input Form</title>
</head>
<body>

<form>
    <div>Name:</div>
    <input type="text" name="personName"/>
    <div>Age:</div>
    <input type="number" name="age"/>
    <div>Town:</div>
    <select name="townId">
        <option value="10">Sofia</option>
        <option value="20">Varna</option>
        <option value="30">Plovdid</option>
    </select>
    <div><input type="submit"/></div>
</form>
<?php var_dump($_GET); ?>

</body>
</html>

 

answered by user john7
...