0

皆さんにさらに質問があります。だから私はPHPが初めてで、これらのエラーに遭遇したときにコードを検証しようとしています:

Notice: Undefined index: newUser[email] in C:\xampp\htdocs\assignment_2\registration.php on line 63

Notice: Undefined index: newUser[ID] in C:\xampp\htdocs\assignment_2\registration.php on line 66

Notice: Undefined index: newUser[password] in C:\xampp\htdocs\assignment_2\registration.php on line 70

質問は、フォーム名が原因でそれをどのように処理するかよくわかりません:(いつものように、どんな助けも大歓迎です:)

これが私の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'];


// 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 "User already exists!";
        }
        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"])){

        // 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 = '<p class="errText">Email must comply with this mask: chars(.chars)@chars(.chars).chars(2-4)</p>';
        // User must be digits and letters
        if(preg_match("/^[0-9a-zA-Z_]{5,}$/", $_POST["newUser[ID]"]) === 0)
          $errUser = '<p class="errText">User must be bigger that 5 chars and contain only digits, letters and underscore</p>';
        // Password must be strong
        //if(preg_match("/^.*(?=.{8,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/", $_POST["pass"]) === 0)
        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>';
      }  
  ?>

        <form action = "<?= $_SERVER['PHP_SELF'] ?>" method= 'POST'> 
            <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>&nbsp;</td>
                        <td>&nbsp;</td> 
                    </tr>          
                </table>
                <input type='submit' name='register' value='Register'>
            </center>    
        </form>
    </body>
</html>
4

3 に答える 3

0

を使うべきだと思います$_POST['newUser']['email']

ただし、PHPのみです。フォームでは、引用符なしでそれらを残すことができます。これは PHP ではなく HTML であるためです。(おもう!)

于 2013-11-08T08:23:39.597 に答える
0

$_POST['newUser']['email']

乾杯

于 2013-11-08T08:30:07.320 に答える