Code must echo back the desired results. please show results. In this PHP exerci
ID: 3766267 • Letter: C
Question
Code must echo back the desired results. please show results.
In this PHP exercise, you will request input from the user, then move the user's response from one file to another and do something with it. Create two separate files. The first will contain a form with three input fields asking for the user's favorite city and the users name and email. Use the post method for the form. Although this file contains no PHP code, on my localhost, it needs the .php extension to successfully call the second file. The second file will contain PHP code to process the user's response. After the user clicks the submit button, echo back Your favorite city is $city and your name is $name., where $city and $name is the input from the form. For the email address, check that it is valid and echo the response with the email entered and the text color to be green if valid and red if not valid. ( See 19.8, page 707 of your text book for reference for this feature of checking the string ) Finally, use a php function to print the date and time. Hint: the variable that contains the user's input is an array. The array variable is $_POST['name'], where 'name' is the name of your input field.
Explanation / Answer
index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<table width="328" border="1">
<tr>
<td width="155"><label>Name</label> </td>
<td width="157"><form id="form1" name="form1" method="post" action="second.php">
<label>
<input name="t1" type="text" id="t1" />
</label>
</td>
</tr>
<tr>
<td>City</td>
<td><label>
<input name="t2" type="text" id="t2" />
</label></td>
</tr>
<tr>
<td colspan="2"><label>
<input type="submit" name="Submit" value="Submit" />
</label></td>
</tr>
</form>
</table>
</body>
</html>
second.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
$name=$_POST['t1'];
$city=$_POST['t2'];
echo $name;
echo $city;
?>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.