Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

php - Why is that my Modal isn't working through html form?

Why is that my Modal is not working? Is it wrong to use POST method? When I load the page and click the link for forgot password and the modal is eventually is display then when I input my email nothing happens. Could someone help me?

This is my PHP script.

<?php
require 'db.php';
$msg='';
if(isset($_POST['submit']))
{
$emailRet = mysqli_real_escape_string($connection, $_POST['emailRetrieve']);

$sql2 = mysqli_query($connection, "SELECT Email_Address, Password FROM pawnshop WHERE Email_Address='".$emailRet."'");

while ($row = mysqli_fetch_array($sql2, MYSQL_ASSOC)) {
    $emailRetrieve = $row['Email_Address'];
    $passwordRetrieve = $row['Password'];
}

  $number = mysqli_num_rows($sql2);
  echo $number;

  if(mysqli_num_rows($sql2) < 1){  
    require 'smtp/Send_Mail.php';

    $to = $emailRetrieve;
    $subject = "PBMS Password Retrieval";
    $body ='Hi, This is your account information<br><br> Username:'.$emailRetrieve.'<br> Password:'.$passwordRetrieve.'';

    Send_Mail($to,$subject,$body);
    $msg='Check your email to get your password';
    echo 'send';
  }
  else
  {
    $msg='Check your email and try again';
  }

}
?>

This is my html code for Modal

    <html>
    <head>
      <link type='text/css' href='css/modal.css' rel='stylesheet' media='screen' />
      <script type='text/javascript' src='js/jqueryModal.js'></script>
      <script type='text/javascript' src='js/jquery.simplemodal.js'></script>
      <script type='text/javascript' src='js/modal.js'></script> 
    </head>
    <body>
    <form method="post">
    <div id='basic-modal'>
              <center>
                 <a href='#' class='basic custom-font-reg'>Forgot password?</a><br>
                 <a href='Registration.php' class='custom-font-reg'>Register for an account?</a>
              </center>
              </div>

              <hr class="hr-custom2">

              <div id="basic-modal-content">
                 <div class="getPasswordWrapper">
                 <hr class="PasswordHeaderColor"></hr>
                 <p class="enterEmailPasswordText">Enter your username to get your password</p>
                 <center>
                      <input type="text" name="emailRetrieve" class="getPassword" placeholder="Your UsernameEmail" required/>
                      <button type="submit" class="getPasswordButton">Send</button>
                      <span><?php echo $msg; ?></span>
                 </center>
                 </div>
              </div>
    </form>
    </body>
    </html>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Firstly, you don't have a submit with the "submit" name attribute to go with $_POST['submit'] and that's the reason why it's failing, so nothing in there if(isset($_POST['submit'])){...} will get executed.

So do this:

<button type="submit" class="getPasswordButton" name="submit">Send</button>

or an input:

<input type="submit" class="getPasswordButton" name="submit" value="Send">

Plus, MYSQL_ASSOC needs to be MYSQLI_ASSOC. You can't mix MySQL functions.

However, looking at if(mysqli_num_rows($sql2) < 1){ that may need to be changed using > operator. Doing < 1 tells MySQL if it does not exist; an insight.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...