Embed necessary php scripts in the following form elements so that they show the
ID: 3871633 • Letter: E
Question
Embed necessary php scripts in the following form elements so that they show the previously entered/selected values
Text Field
Radio Buttons
Checkboxes
Pull Down Menus
Text Areas
Insert into this code:
*form_handle.php
<?php
include '/header.php';
include '/footer.php';
echo $_POST["username"];
echo("<br/>");
echo $_POST["password"];
echo("<br/>");
echo $_POST["about"];
echo("<br/>");
$gender = $_POST["gender"];
if($gender == "male")
{
echo("Male");
}
else if ($radioVal == "female")
{
echo("female");
}
else {
echo("Other");
}
echo("<br/>");
if ( isset($_POST['physics'])) {
echo("physics is selected <br/>");
}
if ( isset($_POST['chemistry'])) {
echo("chemistry is selected <br/>");
}
if ( isset($_POST['maths'])) {
echo("maths is selected <br/>");
}
if ( isset($_POST['economics'])) {
echo("economics is selected <br/>");
}
if ( isset($_POST['biology'])){
echo("biology is selected <br/>");
}
?>
**index.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="form_handle.php" method="post">
<div>
<label for="usernmae">username</label>
<input type = "text" id="username" name="username">
</div>
<div>
<label for="password">password</label>
<input type = "password" id="password" name="password">
</div>
<div>
<label for="about">about me</label>
<textarea id="about" name="about" cols="40" rows="5"></textarea>
</div>
<div>
<fieldset><legend>choose gender:</legend>
<input type="radio" name="gender" id="male" value="male" ><label for="male">Male</label>
<input type="radio" name="gender" id="female" value="female"><label for="female">Female</label>
<input type="radio" name="gender" id="other" value="other"><label for="other">Other</label>
</fieldset>
</div>
<div>
<fieldset><legend>choose subjects:</legend>
<input type="checkbox" class="subject" value="physics" name="physics" id="subject"><label for="physics">physics</label>
<input type="checkbox" class="subject" value="chemistry" name="chemistry" id="subject"><label for="chemistry">chemistry</label>
<input type="checkbox" class="subject" value="maths" name="maths" id="subject"><label for="maths">maths</label>
<input type="checkbox" class="subject" value="economics" name="economics" id="subject"><label for="economics">economics</label>
<input type="checkbox" class="subject" value="biology" name="biology" id="subject"><label for="biology">biology</label>
</fieldset>
</div>
<div>
<input type="submit" value="submit">
<input type="reset" value="reset">
</div>
</form>
</body>
</html>
Explanation / Answer
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="form_handle.php" method="post">
<div>
<label for="usernmae">username</label>
<input type = "text" id="username" name="username">
</div>
<div>
<label for="password">password</label>
<input type = "password" id="password" name="password">
</div>
<div>
<label for="about">about me</label>
<textarea id="about" name="about" cols="40" rows="5"></textarea>
</div>
<div>
<fieldset><legend>choose gender:</legend>
<input type="radio" name="gender" id="male" value="male" ><label for="male">Male</label>
<input type="radio" name="gender" id="female" value="female"><label for="female">Female</label>
<input type="radio" name="gender" id="other" value="other"><label for="other">Other</label>
</fieldset>
</div>
<div>
<fieldset><legend>choose subjects:</legend>
<input type="checkbox" class="subject" value="physics" name="physics" id="subject"><label for="physics">physics</label>
<input type="checkbox" class="subject" value="chemistry" name="chemistry" id="subject"><label for="chemistry">chemistry</label>
<input type="checkbox" class="subject" value="maths" name="maths" id="subject"><label for="maths">maths</label>
<input type="checkbox" class="subject" value="economics" name="economics" id="subject"><label for="economics">economics</label>
<input type="checkbox" class="subject" value="biology" name="biology" id="subject"><label for="biology">biology</label>
</fieldset>
</div>
<div>
<input type="submit" value="submit">
<input type="reset" value="reset">
</div>
</form>
</body>
</html>
$username = trim(mysql_prep($_POST['username']));
$password = trim(mysql_prep($_POST['password']));
$hashed_password = sha1($password);
if ( empty($errors) ) {
// Check database to see if username and the hashed password exist there.
$query = "SELECT id, username, type ";
$query .= "FROM users ";
$query .= "WHERE username = '{$username}' ";
$query .= "AND hashed_password = '{$hashed_password}' ";
$query .= "LIMIT 1";
$result_set = mysql_query($query);
confirm_query($result_set);
if (mysql_num_rows($result_set) == 1) {
// username/password authenticated
// and only 1 match
$found_user = mysql_fetch_array($result_set);
$_SESSION['user_id'] = $found_user['id'];
$_SESSION['username'] = $found_user['username'];
$_SESSION['type'] = $found_user['type'];
redirect_to("content.php");
} else {
// username/password combo was not found in the database
$message = "Username/password combination incorrect.<br />
Please make sure your caps lock key is off and try again.";
}
} else {
if (count($errors) == 1) {
$message = "There was 1 error in the form.";
} else {
$message = "There were " . count($errors) . " errors in the form.";
}
}
} else { // Form has not been submitted.
if (isset($_GET['logout']) && $_GET['logout'] == 1) {
$message = "You are now logged out.";
} elseif (isset($_GET['passwordchanged']) && $_GET['passwordchanged'] == 1) {
$message = "Your password has been successfully changed. Please login with your new password.";
}
$username = "";
$password = "";
}
?>
<?php include("includes/header.php"); ?>
<div id="navwrapper">
<?php echo main_nav(NULL); ?>
</div>
<div id="page">
<h2>Login</h2>
<?php if (!empty($message)) {echo "<p class="message">" . $message . "</p>";} ?>
<?php if (!empty($errors)) { display_errors($errors); } ?>
<form action="login.php" method="post">
<table>
<tr>
<td>Username:</td>
<td><input type="text" name="username" maxlength="30" value="<?php echo htmlentities($username); ?>" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" maxlength="30" value="<?php echo htmlentities($password); ?>" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Login" /></td>
</tr>
</table>
</form>
</div>
<?php include("includes/footer.php"); ?>
<?php
include '/header.php';
include '/footer.php';
echo $_POST["username"];
echo("<br/>");
echo $_POST["password"];
echo("<br/>");
echo $_POST["about"];
echo("<br/>");
$gender = $_POST["gender"];
if($gender == "male")
{
echo("Male");
}
else if ($radioVal == "female")
{
echo("female");
}
else {
echo("Other");
}
echo("<br/>");
if ( isset($_POST['physics'])) {
echo("physics is selected <br/>");
}
if ( isset($_POST['chemistry'])) {
echo("chemistry is selected <br/>");
}
if ( isset($_POST['maths'])) {
echo("maths is selected <br/>");
}
if ( isset($_POST['economics'])) {
echo("economics is selected <br/>");
}
if ( isset($_POST['biology'])){
echo("biology is selected <br/>");
}
?>
<?php require_once("includes/session.php"); ?>
<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php
if (logged_in()) {
redirect_to("content.php");
}
include_once("includes/form_functions.php");
// START FORM PROCESSING
if (isset($_POST['submit'])) { // Form has been submitted.
$errors = array();
// perform validations on the form data
$required_fields = array('username', 'password');
$errors = array_merge($errors, check_required_fields($required_fields, $_POST));
$fields_with_lengths = array('username' => 30, 'password' => 30);
$errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST));
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.