Php Code Given Exercise 3 Exercise 3 Form Div Margin Top 10px Label Display Inline Block W Q43810102

PHP code given for exercise-3 :
<?php
session_start();
if(!isset($_SESSION[‘names’])) {
$_SESSION[‘names’] = array(
‘John Smith’,
‘Jane Smith’,
‘Ben Smith’
‘Lachlan Smith’,
);
} else if(isset($_POST[‘submit’])) {}
$name = $_POST[‘fname’] . ‘ ‘;
$name .= $_POST[‘lname’];
$_SESSION[‘names’][] = $name
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset=”utf-8″>
<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
<title>Exercise 3</title>
<style>
form > div {margin-top:10px;}
label {display: inline-block; width:150px;}
</style>
</head>
<body>
<h1>List of Names</h1>
<ul>
<?php for($i = 0; $i<5; $i++): ?>
<li><?php echo $_SESSION[$i];?></li>
<?php endfor;?>
</ul>
<form method=”POST” action=”<?php echohtmlspecialchars($_SERVER[‘PHP_SELF’]);?>”>
<div>
<label for=”fname”>First Name</label>
<input type=”text” name=”fname” id=”fname”>
</div>
<div>
<label for=”lname”>Last Name</label>
<input type=”text” name=”lname” id=”lname”>
</div>
<div>
<input type=”submit” value=”Submit” name=”submit”>
</div>
</form>
</body>
</body>
</html>
You have been given the file exercise-3.php. This file has a mix of HTML and PHP. The PHP code has syntax and logical errors. Once debugged the page should list all the names initially presented within the $_SESSION variable and any additional names added through the form present on the page. As you do not have a debug environment, you have to rely on traditional methods of debugging. Desk checking, tracing (echo out messages), or variable inspection with var_dump(<variable»). Note: Debugging is more than just making sure the syntax is correct. Sometimes, you have to rewrite parts of code to correct the logic. You will have to do this in this example, but only minor changes are needed Show transcribed image text You have been given the file exercise-3.php. This file has a mix of HTML and PHP. The PHP code has syntax and logical errors. Once debugged the page should list all the names initially presented within the $_SESSION variable and any additional names added through the form present on the page. As you do not have a debug environment, you have to rely on traditional methods of debugging. Desk checking, tracing (echo out messages), or variable inspection with var_dump(
Expert Answer
Answer to PHP code given for exercise-3 : Exercise 3 form > div {margin-top:10px;} label {display: inline-block; width:150px;} Lis…
OR