我有一些我不太明白的错误。以下错误是:
Notice: Undefined index: newUser in C:\xampp\htdocs\assignment_2\registration.php on line 24
Notice: Undefined index: newUser in C:\xampp\htdocs\assignment_2\registration.php on line 63
Notice: Undefined index: newUser in C:\xampp\htdocs\assignment_2\registration.php on line 67
Notice: Undefined index: newUser in C:\xampp\htdocs\assignment_2\registration.php on line 71
这很奇怪,因为我昨天发誓不存在错误,我还在 netbeans 中进行了历史比较,结果还是一样:(
这是我的registration.php的样子:
<html>
<h4>
<center>
New User Registration
</center>
</h4>
<body>
<?php
/*
* What this code does, is it takes the users registration information, and stores it in a file.
* After that what I hope to do is to retrive the same file when the user is on the login page and if
* the login matches whats in the file, then proceed to the invoice page.
*/
include "functions.inc";
// Define the datafile to hold the $users array
$datafile = "users.dat";
// See if the user has submitted something
if (array_key_exists('register', $_POST))
{
// Get the new user info
$the_user = $_POST['newUser']['ID'];
// Load the file of users and store it in $users
$users = arrayfile_to_array($datafile);
// Validate user name and password
if (user_exists($the_user['ID'], $users))
{
echo "<p><center>Please fill in all text boxes</center></p>";
}
else
{
// If valid, save to the file of users
$users[] = $the_user;
array_to_arrayfile($users, $datafile);
}
}
else
{
if (!file_exists($datafile)) // Data file doesn't exist, so create it
{
$users = array();
array_to_arrayfile($users, $datafile);
}
}
?>
<?php
// my defined error values
$errEmail = "";
$errUser = "";
$errPass = "";
if(isset($_POST["register"])){
// User must be digits and letters
if(preg_match("/^[0-9a-zA-Z]{5,}$/", $_POST['newUser']['ID']) === 0)
$errUser = '<span class="error">Username must be more than 5 characters and contain letters and numbers.</span>';
// Password must be strong
if(preg_match("/^.*(?=.{8,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/", $_POST['newUser']['password']) === 0)
$errPass = '<span class="error">Password must be at least 8 characters and must contain at least one lower case letter, one upper case letter and one digit</span>';
//Email validation
if(preg_match("/^[a-zA-Z]\w+(\.\w+)*\@\w+(\.[0-9a-zA-Z]+)*\.[a-zA-Z]{2,4}$/", $_POST['newUser']['email']) === 0)
$errEmail = '<span class="error">example: chars(.chars)@chars(.chars).chars(2-4)</span>';
}
?>
<form action = "invoice.php" method= 'get'>
<center>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td>Username</td>
<td>:</td>
<td ><input name="newUser[ID]" type="text" size="16" value="">
<?php if(isset($errUser) and $errUser !='') echo $errUser; ?>
</td >
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="newUser[password]" type="password" size="16" value="">
<?php if(isset($errPass) and $errPass !='') echo $errPass; ?>
</td >
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="newUser[email]" type="text" size="50" value="">
<?php if(isset($errEmail) and $errEmail !='') echo $errEmail; ?>
</td >
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<input type='submit' name='register' value='Register'><br>
</center>
</form>
</body>
</html>
任何帮助将不胜感激。谢谢!