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 Username\Email" required/>
<button type="submit" class="getPasswordButton">Send</button>
<span><?php echo $msg; ?></span>
</center>
</div>
</div>
</form>
</body>
</html>
Your form must have an action
attribute. Its value must be the name of the script file that handle the form.
<form action="your/php/script.php" method="post">
or, if the php script is on the same page with the form, you can write:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.