Joseph Witchard
09-03-2008, 04:09 PM
Form Processing:
<?php
// include the connection settings
define('DB_HOST', 'host');
define('DB_USER', 'user');
define('DB_PWD', 'password');
define('DB_NAME', 'database');
// connect to the database
$conn = new mysqli(DB_HOST, DB_USER, DB_PWD, DB_NAME);
// process the form
if (array_key_exists('login', $_POST) && !empty($_POST['login'])) {
// create an empty array for missing fields
$missing = array();
/* here, I'm going to create an
array to hold the form fields.
if the form fields are empty,
I'll add them to the $missing
array. */
$fields = array("F_Username" => $_POST['username'], "F_Pwd" => $_POST['pwd']);
foreach($fields as $field => $value) {
if (empty($field)) {
array_push($missing, $field);
}
}
// if $missing is empty, continue the processing
if (empty($missing)) {
// assign the form fields to variables
$username = $fields["F_Username"];
$pwd = $fields["F_Pwd"];
// clean up the input
$username = htmlentities($username, ENT_QUOTES, 'UTF-8');
$pwd = htmlentities($pwd, ENT_QUOTES, 'UTF-8');
$query = "SELECT user_id, username, pwd FROM users WHERE username='$username' AND pwd ='$pwd'";
// prepare the statement
if ($stmt = $conn->prepare($query)) {
// execute
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows < 3) {
exit;
}
// bind the result
$stmt->bind_result($user_ID1, $username1, $pwd1);
// store the result
// fetch the values
while ($stmt->fetch()) {
session_set_cookie_params(900);
session_start();
$_SESSION['id'] = $user_ID1;
$_SESSION['username'] = $username1;
$_SESSION['pwd'] = $pwd1;
header("Location: http://uhrebirth.com/staff/admin_center.php");
}
// close the statement
$stmt->close();
// close the connection
$conn->close();
}
}
}
?>
HTML Form:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Rebirth Test Page</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="cache-control" content="no-cache">
<link href="/css/general.css" rel="stylesheet" type="text/css">
</head>
<body>
<div align="center">
<form id="AdminLogIn" name="AdminLogIn" method="post" action="/staff/admin_process.php">
<input type="text" id="username" name="username"><br>
<label for="username">Username</label><br>
<input type="password" id="pwd" name="pwd"><br>
<label for="password">Password</label>
<br><br>
<input type="submit" id="login" name="login" value="Login">
<input type="reset" value="Reset"><br><br>
</form>
</div>
</body>
</html>
Every time I submit the form, I get taken to the processing page, which does nothing more than display a blank white window in my browser. It's like it doesn't even attempt to send me to the Admin Page, and it's like the processing page doesn't process anything at all. I would think that maybe it's because the action attribute sends it to an external page instead of submitting the form to its page with PHP included above the doctype (I've always had trouble with the former, for some reason), but it does the same thing either way. Can I get some help?
<?php
// include the connection settings
define('DB_HOST', 'host');
define('DB_USER', 'user');
define('DB_PWD', 'password');
define('DB_NAME', 'database');
// connect to the database
$conn = new mysqli(DB_HOST, DB_USER, DB_PWD, DB_NAME);
// process the form
if (array_key_exists('login', $_POST) && !empty($_POST['login'])) {
// create an empty array for missing fields
$missing = array();
/* here, I'm going to create an
array to hold the form fields.
if the form fields are empty,
I'll add them to the $missing
array. */
$fields = array("F_Username" => $_POST['username'], "F_Pwd" => $_POST['pwd']);
foreach($fields as $field => $value) {
if (empty($field)) {
array_push($missing, $field);
}
}
// if $missing is empty, continue the processing
if (empty($missing)) {
// assign the form fields to variables
$username = $fields["F_Username"];
$pwd = $fields["F_Pwd"];
// clean up the input
$username = htmlentities($username, ENT_QUOTES, 'UTF-8');
$pwd = htmlentities($pwd, ENT_QUOTES, 'UTF-8');
$query = "SELECT user_id, username, pwd FROM users WHERE username='$username' AND pwd ='$pwd'";
// prepare the statement
if ($stmt = $conn->prepare($query)) {
// execute
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows < 3) {
exit;
}
// bind the result
$stmt->bind_result($user_ID1, $username1, $pwd1);
// store the result
// fetch the values
while ($stmt->fetch()) {
session_set_cookie_params(900);
session_start();
$_SESSION['id'] = $user_ID1;
$_SESSION['username'] = $username1;
$_SESSION['pwd'] = $pwd1;
header("Location: http://uhrebirth.com/staff/admin_center.php");
}
// close the statement
$stmt->close();
// close the connection
$conn->close();
}
}
}
?>
HTML Form:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Rebirth Test Page</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="cache-control" content="no-cache">
<link href="/css/general.css" rel="stylesheet" type="text/css">
</head>
<body>
<div align="center">
<form id="AdminLogIn" name="AdminLogIn" method="post" action="/staff/admin_process.php">
<input type="text" id="username" name="username"><br>
<label for="username">Username</label><br>
<input type="password" id="pwd" name="pwd"><br>
<label for="password">Password</label>
<br><br>
<input type="submit" id="login" name="login" value="Login">
<input type="reset" value="Reset"><br><br>
</form>
</div>
</body>
</html>
Every time I submit the form, I get taken to the processing page, which does nothing more than display a blank white window in my browser. It's like it doesn't even attempt to send me to the Admin Page, and it's like the processing page doesn't process anything at all. I would think that maybe it's because the action attribute sends it to an external page instead of submitting the form to its page with PHP included above the doctype (I've always had trouble with the former, for some reason), but it does the same thing either way. Can I get some help?