duandi4815 2013-06-23 02:44
浏览 41
已采纳

数据库中的数组错误

I've got an array of usernames that needs to be matched with a db table upon post.

When I post it, I get the following error:

Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in /hermes/waloraweb008/b2049/information/folder/page.php on line 43 post_ok|213

This creates the array after the @sign (Works fine.):

$data = preg_replace('!((@)([-a-zA-Zа-яА-Я()0-9@:%_+.~#?&;//=]+))!i', '<a href="user.php?u=$3">$1</a>', $data);
$mentions = preg_match_all('!((@)([-a-zA-Zа-яА-Я()0-9@:%_+.~#?&;//=]+))!i', $data, $matches);
foreach ($matches as $findnames)
    {
        $shiz = implode(',',$findnames);
    }

This is what I want to check for the array within the db.

$mentionsql = "SELECT * FROM users WHERE username IN '$shiz'";
$mentionquery = mysqli_query($db_conx, $mentionsql);
$row83 = mysqli_fetch_row($mentionquery);
$musername = $row83["username"];

So that I can later do this:

mysqli_query($db_conx, "INSERT INTO notifications(username, initiator, app, which_status,did_read, date_time) 
                        VALUES('$musername','$log_username','<a href=user.php?u=$log_username>$log_username</a> mentioned you in a status.','$statusid',now(),now())");

Any ideas as to why there is an error?

  • 写回答

1条回答 默认 最新

  • dongyinglan8707 2013-06-23 03:10
    关注

    As far as I can interpret your code $shiz is a comma-separated string of usernames, so: $shiz == 'user1, user2, user3'

    on this line you are generating your query:

    $mentionsql = "SELECT * FROM users WHERE username IN '$shiz'";
    

    if you insert my example of $shiz you get a query like this:

    "SELECT * FROM users WHERE username IN 'user1, user2, user3'"
    

    However, the actual syntax for the SQL command In requires round brackets. Furthermore, if the usernames are strings, you need to put them in single quotes. So your query should look like this:

    "SELECT * FROM users WHERE username IN ('user1', 'user2', 'user3')"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大