[英]what is wrong with this php code shown as below?
在下面的代碼中,else部分工作正常,但如果電子郵件不在數據庫中,為什么javascript警報---('此電子郵件ID不存在於我們的記錄中')不起作用? 。 如果else部分正在工作,為什么num_rows = 0不起作用。 我嘗試了很多。 我們將不勝感激。
<?php
include 'db.php';
$em = $_POST['email'];
$qry = mysql_query("select * from user where email_id='$em' ")or die(mysql_error());
$num = mysql_num_rows($qry);
if(is_null($num))
{
?>
<script type="text/javascript">
alert('This email id doesn't exist in our records');
</script>
<?php
}
else
{
while ($row = mysql_fetch_array($qry))
{
$email_id = $row['email_id'];
$name = $row['user_login_id'];
$password= $row['password'];
}
if($email_id)
{
$to= $email_id;
$subject=" Password Recovery Mail";
$message="Let US REMIND YOU!! Your username - ".$name. " and Password - ".$password;
$header = "MIME-Version: 1.0" . "\r\n";
$header .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$header.="From:<donotreply@jassasia.com>"."\r\n";
$n=mail($to,$subject,$message,$header);
?> <script type="text/javascript">
alert('Check your Mail, <?php echo $email_id; ?>, for your username and password');
window.location="index.php";
</script>
<?php
}
}
?>
<div class="container">
<div class="row">
<div class="col-md-8"><br/>
<div class="col-md-12" style="border:1px solid #ddd;"><br/>
<form class="form-horizontal" action="" method="POST">
<h2>Hope you remember your registered email id...</h2>
<div class="form-group">
<label class="col-sm-5 control-label">Enter the registered email id</label>
<div class="col-sm-2">
<input type="email" name="email" autocomplete="off" id="" placeholder="Enter the email id " required autofocus>
<input type="submit" id="sub" name="forgotpass" value="Continue">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
改變這一點
if(is_null($num))
對此
if(empty($num))
和
改變這一點
if($email_id)
對此
if(isset($email_id))
我會先檢查控制台消息,因為我認為你的警報功能根本不起作用,即使它出現了你在文本中使用的原因。
改變這個
alert('This email id doesn't exist in our records');
至
alert("This email id doesn't exist in our records"); // See the "
干杯
將變量$ num與0和FALSE進行比較。 由於mysql_num_rows函數在成功時返回整數,因此在失敗時返回FALSE。
if( $num ==0 && $num!=FALSE)
並檢查$ email agains empty或isset
if(isset($email) && $email!="")
$num = mysql_num_rows($qry);
為您提供其他行檢索的計數數,否則為FALSE
,表示0條記錄。
所以當你檢查if(is_null($num))
它永遠不會輸入if子句,因為mysql_num_rows($qry);
永遠不會返回NULL
。
你需要改變它
<? if($num == FALSE)
{
?>
<script type="text/javascript">
alert('This email id doesn't exist in our records');
</script>
首先要在PHP代碼中引入Javascript警告框,你需要調用一個函數。 請嘗試以下代碼
<script type="text/javascript">
function show_alertMsg() {
var msg = "This email id doesn't exist in our records.";
alert(msg);
}
</script>
if(is_null($num))
{
echo '<script type="text/javascript"> show_alertMsg(); </script>';
}
else {
// your code
}
嘗試這個
<?php
include 'db.php';
$em = $_POST['email'];
$qry = mysql_query("select * from user where email_id='$em' ")or die(mysql_error());
if( mysql_num_rows($qry) < 0)
{
?>
<script type="text/javascript">
alert('This email id doesn't exist in our records');
</script>
<?php
}
else
{
while ($row = mysql_fetch_array($qry))
{
$email_id = $row['email_id'];
$name = $row['user_login_id'];
$password= $row['password'];
}
if($email_id)
{
$to= $email_id;
$subject=" Password Recovery Mail";
$message="Let US REMIND YOU!! Your username - ".$name. " and Password - ".$password;
$header = "MIME-Version: 1.0" . "\r\n";
$header .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$header.="From:<donotreply@jassasia.com>"."\r\n";
$n=mail($to,$subject,$message,$header);
?> <script type="text/javascript">
alert('Check your Mail, <?php echo $email_id; ?>, for your username and password');
window.location="index.php";
</script>
<?php
}
}
?>
<div class="container">
<div class="row">
<div class="col-md-8"><br/>
<div class="col-md-12" style="border:1px solid #ddd;"><br/>
<form class="form-horizontal" action="" method="POST">
<h2>Hope you remember your registered email id...</h2>
<div class="form-group">
<label class="col-sm-5 control-label">Enter the registered email id</label>
<div class="col-sm-2">
<input type="email" name="email" autocomplete="off" id="" placeholder="Enter the email id " required autofocus>
<input type="submit" id="sub" name="forgotpass" value="Continue">
</div>
</div>
</form>
</div>
</div>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.