这段PHP代码的错误如下所示
what is wrong with this php code shown as below?
在下面的代码中,else部分工作正常,但如果电子邮件不在数据库中,为什么javascript警报-('此电子邮件id不存在于我们的记录')不工作?. 如果其他部分正在工作,为什么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>
change this
if(is_null($num))
if(empty($num))
和
change this
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)
AND检查$email是否为空或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>
首先介绍Javascript警报框,在PHP代码中需要调用一个函数。试试下面的代码
<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
}
try this
<?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>
相关文章:
- 尝试在PHP中回显输入文本时出现未定义的索引错误
- 巨大的数据和PHP错误
- AJAX简单错误.XMLHttpRequest无法加载http://localhost/mpl/getPage.php.
- PHP REST服务抛出异常——希望避免控制台错误
- 使用javascript ajax post方法的未定义偏移PHP错误
- JQuery Ajax PHP中的错误和成功处理
- data.php:1未捕获的语法错误:意外的令牌:
- 如何“;修复解析错误:语法错误,意外'{'in”用于php
- JSON3中的Facebook xd_arbiter.php错误
- 将 PHP 输出到 JavaScript 时出现语法错误
- PHP 显示错误的名称值
- PHP 删除错误
- 通过 Ajax 向 PHP 发送错误的数据
- PHP&jQuery联系人表单错误
- ajax和json错误.php帖子错误
- 服务器间错误:php访问动态创建的元素数组
- PHP 嵌入式 JavaScript 解析错误 PHP 标签导致“语法错误:预期的表达式,得到<”
- 访问不同的数据库,防止用户错误PHP
- 错误/错误PHP SIMPLE HTML DOM PARSER
- 防止重复条目-Ajax未返回错误.PHP MySQL jQuery