我想知道我的checkLogin.php的代码放在哪里,所以当我点击注册时它会把它们带到注册表中。我不确定应该在哪里放置代码,或者应该使用哪些命令进行设置,以便在单击注册按钮时不会告诉我我没有填写用户名或密码。登录和注册php程序
checkLogin.php:
<?php
/* connection info */
ini_set("display_errors","on");
error_reporting(E_ALL | E_STRICT);
ini_set("include_path","../../includes");
include("dbinfo.inc");
$cxn = mysqli_connect($host,$user,$password,$dbname)
or die("Couldn't connect to server.");
?>
<?php
/* Program name: checkLogin.php
* Description: Program displays the blank form and checks
* all the form fields for blank fields.
*/
if(isset($_POST['submitted']) and $_POST['submitted'] == "yes")
{
foreach($_POST as $field => $value)
{
if(empty($value))
{
$blank_array[] = $field;
}
else
{
$good_data[$field] = strip_tags(trim($value));
}
}
if(@sizeof($blank_array) > 0)
{
$message = "<p style='color: red; margin-bottom: 0;
font-weight: bold'>
You didn't fill in one or more required fields.
You must enter:
<ul style='color: red; margin-top: 0;
list-style: none' >";
/* display list of missing information */
foreach($blank_array as $value)
{
$message .= "<li>$value</li>";
}
$message .= "</ul>";
echo $message;
extract($good_data);
include("login.inc");
exit();
}
foreach($_POST as $field => $value)
{
if(!empty($value))
{
$user_patt = "/^[A-Za-z0-9]{8,20}$/";
$pass_patt = "/^[A-Za-z0-9*[email protected]$&]{8,12}$/";
if(preg_match("/user/i",$field))
{
if(!preg_match($user_patt,$value))
{
$error_array[] = "$value is an invalid $field";
}
}
if (preg_match("/pass/i",$field))
{
if(!preg_match($pass_patt, $value))
{
$error_array[] = "Invalid $field";
}
}
}
$clean_data[$field] = strip_tags(trim($value));
}
if(@sizeof($error_array) > 0)
{
$message = "<ul style='color: red; list-style: none' >";
foreach($error_array as $value)
{
$message .= "<li>$value</li>";
}
$message .= "</ul>";
echo $message;
extract($clean_data);
include("login.inc");
exit();
}
else
{
foreach($good_data as $field => $value)
{
$clean_data[$field] = mysqli_real_escape_string($cxn,$value);
}
$sql = "SELECT * from UserInfo where username='$clean_data[username]' and
password='$clean_data[password]'";
$result = mysqli_query($cxn,$sql) or die("<p>Couldn't connect to login server</p>");
$row = mysqli_fetch_assoc($result);
if ($row > 0)
{
$sql2 = "UPDATE TimeStamp SET time = CURRENT_TIMESTAMP where username='$clean_data[username]'";
$result2 = mysqli_query($cxn,$sql2) or die("<p>Couldn't connect to login server</p>");
include('goodLogin.inc');
}
else
{
echo $message;
extract($clean_data);
include('login.inc');
exit();
}
}
}
else
{
include("login.inc");
}
?>
login.inc:
<?php
echo "<form action='$_SERVER[PHP_SELF]' method='POST'>";
echo "<h2>Login Form</h2>";
foreach ($labels as $field => $label)
if($field != "password")
{
echo "<div class='field'>
<label for='$field'>$label</label>
<input id='$field' name='$field' type='text' value='"[email protected]$$field."'
size='42' /></div>";
}
else
{
echo "<div class='field'>
<label for='$field'>$label</label>
<input id='$field' name='$field' type='password' maxlength='20' value='"[email protected]$$field."' size='42' />";
echo "</div>";
}
echo "<div id='submit'>
<input type='hidden' name='submitted' value='yes'>
<input type='submit' value='$login'></div>
<h4>If you are new click register</h4>";
echo "<div id='register'>
<input type='submit' value='$register' a href='register.php'></div>";
echo "</form>";
?>
Register.php:
<?php
/* Program name: form_inc
* Description: Defines the Form to display a user's information
*/
$labels = array (
"username" => "Username",
"password" => "Password",
"first_name" => "First Name",
"last_name" => "Last Name",
"city" => "City",
"email" => "E-mail",);
$country = array (
"select" => "",
"us" => "United States",
"ca" => "Canada",
"mx" => "Mexico",);
$register = "Register";
?>
<html>
<head>
<meta charset="utf-8">
<title>Exercise 3 Order Form</title>
<style type=>
form {
margin: 5em auto 8em;
padding: 0;
}
h2 {
text-align: center;
}
form {
float: left;
width: 450px;
padding-left: 20px;
padding-bottom: 10px;
border: solid 2px #CCC;
text-align: left;
}
.field {
padding-top: .5em;
padding-botton: 2em;
}
label {
font-weight: bold;
float: left;
width: 20%;
margin-right: 1em;
text-align: right;
}
#submit {
float: left;
margin-top: 4%;
margin-left: 2%;
}
#register {
float: right;
margin-top: 2%;
margin-right: 2.5%;
}
h4 {
margin-left: 42%;
}
</style>
</head>
<body>
<?php
echo "<form action='$_SERVER[PHP_SELF]' method='POST'>";
echo "<h2>Registration Form</h2>";
foreach ($labels as $field => $label)
{
echo "<div class='field'>
<label for='$field'>$label</label>
<input id='$field' name='$field' type='text' value='"[email protected]$$field."'
size='42' /></div>";
if($field == "city") {
echo "<div class='field'>";
echo "<label for='country'>Country</label>
<select id='country' name='country'>";
foreach ($country as $select => $option)
{
echo "<option value='$select'>$option</option>";
}
echo "</select></div>";
}
}
echo "<div id='register'>
<input type='submit' value='$register'></div>";
echo "</form>";
?>
首先什么是你的问题?请用简单的线条指定,也可以输入完整的代码。不是它的一部分。如果你在代码本身中评论你的问题会更好。谢谢 –
我不确定如何或在哪里放置告诉程序取出登录表单并放入registration.inc表单的部分? –
如果没有看到完整的代码,这个问题是不可能回答的。你已经发布了一段以'else {'开头的代码块,而且没有bueno。 –