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 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探