+3 votes
in Class 12 by kratos

Create a form to accept the name of the user as input as shown.

If the user leaves the inputbox blank then it should display error as shown

and if user enters name then it should display as shown below

1 Answer

+4 votes
by kratos
 
Best answer

.error{*****:#FF0000} <?php $name = ""; $nameErr = ""; $flag=0; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { $nameErr = "Name is required"; } else { $flag=1; } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> " method="post"> Name: * <?php echo $nameErr;?>

<?php if($flag==1) { echo "Hello".test_input($_POST["name"]); } ?>

...