Reputation: 3
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?
Upvotes: 0
Views: 48
Reputation: 1968
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')"
Upvotes: 1