dongyuduan1890 2017-04-19 02:23
浏览 24
已采纳

电子邮件确认页面返回错误

I'm making a email confirmation page but when the user clicks the link in the email it bring them to the accept page. When the page loads however it returns with this error.

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, object given in /home/gener105/public_html/email_confirm.php on line 15

<?php 
include 'includes/dbh.php';

$username = $_GET['username'];
$code  =$_GET['code'];

$sql= "SELECT * FROM users WHERE username='$username'";

$result= mysqli_query($conn, $sql);

if (! $result){
   throw new My_Db_Exception('Database error: ' . mysql_error());
}

while($row = mysql_fetch_assoc($result))  {
    $db_code = $row['confirm_code'];
}

if($code == $db_code) {
    $sql2 = "UPDATE users SET confirmed=1 WHERE username='$username'";
    $result2 = mysqli_query($conn, $sql2);

    $sql3 = "UPDATE users SET confirm_code=0 WHERE username='$username'";
    $result3 = mysqli_query($conn, $sql3);
    echo "It worked!";

} else {
  echo "Error: Username and code dont match!";
}

?>

I know its talking about the while statement but I been researched what its talking about and I'm confused I thought the $result variable is what should be the parameter.

  • 写回答

1条回答 默认 最新

  • dtj88302 2017-04-19 02:37
    关注

    You use mysql_fetch_assoc to get results, but execute query with mysqli extension

     $result= mysqli_query($conn, $sql);
    

    replace

    mysql_fetch_assoc
    

    to

    mysqli_fetch_assoc
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?