Pre-populate form with SQL using Cookies or Session?
So, I am trying to make a form where some of it is already filled in if a user is signed in. The first 4 fields (a couple of text fields, a radio button field, and a check box field) would be pre-populated, based on what the person had submitted for their "register" form. The rest of this second form would be some check boxes, and a couple of text fields.
So, would the best way to do this be to set a cookie when they sign in? The sign in page is like this:
Code:
<?php
// check for required fields from the form
if ((!isset($_POST['email'])) || (!isset($_POST['password']))) {
header("Location: userlogin.html");
exit;
}
//connect to server and select database
$mysqli = mysqli_connect("localhost", "accessi4_lara", "buster77", "accessi4_ftoo362")
or die(mysqli_error());
// use mysqli_real_escape_string to clean the input
$email = mysqli_real_escape_string($mysqli, $_POST['email']);
$password = mysqli_real_escape_string($mysqli, $_POST['password']);
//create and issue the query
$sql = "SELECT username FROM frmak_form_1 WHERE
email = '".$email."' AND
password = '".$password."' ";
$result = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli));
// get the number of rows in the result set; should be 1 if a match
if (mysqli_num_rows($result) == 1) {
while ($info = mysqli_fetch_array($result)) {
$username = stripslashes($info['userName']);
}
// set authorization cookie
setcookie("auth", "1", 0, "/", "accessibilityscout.com", 0);
//create display string
$display_block = "
<p>".$username." is authorized! </p>
<p>Authorized Users' Menu: </p>
<ul>
<li><a href=\"submitReview.php\">Click here to submit a review! </a></li>
</ul>
";
} else {
//redirect back to the login form if not authorized
header("Location: userlogin.html");
exit;
}
// close connection to MySQL
mysqli_close($mysqli);
?>
<!DOCTYPE html>
<html>
<head>
<title>User Login</title>
</head>
<body>
<?php echo $display_block; ?>
</body>
</html>
Or would I set a session? And what would be the syntax for doing such. I am trying to self-teach this PHP/MySQL stuff, and I'm having a rough time with this part. If anyone could just point me toward a good tutorial, that would be great. Thanks!