За последние 24 часа нас посетили 69412 программистов и 11607 роботов. Сейчас ищут 2280 программистов ...

Что не так?

Тема в разделе "PHP для новичков", создана пользователем Lucius Vorenus, 23 янв 2018.

  1. Lucius Vorenus

    Lucius Vorenus Новичок

    С нами с:
    23 янв 2018
    Сообщения:
    2
    Симпатии:
    0
    Начал изучать php и читаю книгу PHP for the web (fourth edition) некого Ларри Улмана.

    При изучении возникла проблема.

    Код html

    Код (Text):
    1. <h2>Registration Form <small class="text-muted">23.01.2018</small></h2><!-- Registration Form -->
    2.  
    3. <p>Please complete this form to register</p>
    4.  
    5.     <form action="handle_reg.php" method="post">
    6.         <div class="form-group">
    7.             <label for="InputEmail1">Email Address</label>
    8.             <input type="email" name="email" class="form-control" id="InputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
    9.         </div>
    10.         <div class="form-group">
    11.             <label for="InputPassword1">Password</label>
    12.             <input type="password" name="password" class="form-control" id="InputPassword1" placeholder="Password">
    13.         </div>
    14.         <div class="form-group">
    15.             <label for="InputPassword2">Confirm Password</label>
    16.             <input type="password" name="confirm" class="form-control" id="InputPassword2" placeholder="Confirm Password">
    17.         </div>
    18.         <div class="form-group">
    19.             <label for="InputYear">Year You Were Born</label>
    20.             <input type="text" name="year" class="form-control" id="InputYear" placeholder="YYYY" value="YYYY">
    21.         </div>
    22.         <div class="form-group">
    23.         <label class="my-1 mr-2" for="inlineFormCustomSelectPref">Favorite Color</label>
    24.         <select class="custom-select my-1 mr-sm-2" id="inlineFormCustomSelectPref">
    25.             <option selected>Choose...</option>
    26.             <option value="red">Red</option>
    27.             <option value="yellow">Yellow</option>
    28.             <option value="green">Green</option>
    29.             <option value="blue">Blue</option>
    30.         </select>
    31.         </div>
    32.         <div class="form-group">
    33.         <div class="custom-control custom-checkbox">
    34.             <input type="checkbox" name="confirm" class="custom-control-input" id="customCheck1">
    35.             <label class="custom-control-label" for="customCheck1">I agree to the terms</label>
    36.         </div>
    37.         </div>
    38.         <button type="submit" class="btn btn-primary">Register</button>
    39.     </form>
    40.  
    41. <hr>
    ПХП

    Код (Text):
    1. echo '<h1>Registration Results</h1>';
    2.  
    3. // Flag variable to track success
    4. $okay = true;
    5.  
    6. // Validate email
    7. if (empty($_POST['email'])) {
    8.     echo '<div class="alert alert-danger" role="alert">Please enter your email address.</div>';
    9.     $okay = false;
    10. }
    11.  
    12. // Validate password
    13. if (empty($_POST['password'])) {
    14.     echo '<div class="alert alert-danger" role="alert">Please enter your password.</div>';
    15.     $okay = false;
    16. }
    17.  
    18. // Validate the two passwords for equality
    19. if ($_POST['password'] != $_POST['confirm']) {
    20.     echo '<div class="alert alert-danger" role="alert">Your confirmed password does not match to the original password.</div>';
    21.     $okay = false;
    22. }
    23.  
    24. // Validate the birth year {
    25. if (is_numeric($_POST['year'])) {
    26.     $age = 2018 - $_POST['year']; //Calculate age this year
    27. }
    28. else {
    29.     echo '<div class="alert alert-danger" role="alert">Please enter the year You were born as four digits.</div>';
    30.     $okay = false;
    31. }
    32.  
    33. // Check that they were born before this year
    34.  
    35. if ($_POST['year'] >= 2018) {
    36.     echo '<div class="alert alert-danger" role="alert">Either you entered your birth year wrong or you come from the future!</div>';
    37.     $okay = false;
    38. }
    39.  
    40. // If there no errors, print a success message
    41.  
    42. if ($okay) {
    43.     echo "<p>You have been successfully registered (but not really).</p><p>You will turn $age this year.</p>";
    44. }
    Проблема конкретно вот с этим:

    Код (Text):
    1. // Validate the two passwords for equality
    2. if ($_POST['password'] != $_POST['confirm']) {
    3.     echo '<div class="alert alert-danger" role="alert">Your confirmed password does not match to the original password.</div>';
    4.     $okay = false;
    5. }
    Даже при вводе двух одинаковых паролей все равно выводит сообщение о том что они не совпадают.

    В чем причина? Заранее, спасибо.
     
  2. Lucius Vorenus

    Lucius Vorenus Новичок

    С нами с:
    23 янв 2018
    Сообщения:
    2
    Симпатии:
    0
    Проблему решил, спасибо.
     
  3. TeslaFeo

    TeslaFeo Старожил

    С нами с:
    9 мар 2016
    Сообщения:
    2.971
    Симпатии:
    753
    причина в том, что они не совпадают :)

    P. S. названия для тем нужно придумывать более информативные.