0

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
  • Echo out your SQL statement, and see what it looks like. Commented Jun 23, 2013 at 2:47

1 Answer 1

1

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')"
Sign up to request clarification or add additional context in comments.

2 Comments

Aaaaah I see. I'll get to work on that. Any idea on how to make that happen?
First, you need to replace the single-quotes in $mentionsql = "SELECT * FROM users WHERE username IN '$shiz'"; with round brackets. Second, if your usernames are not escaped with single-quotes, you could change your implode call to $shiz = "'".implode("','",$findnames)."'". My PHP skills are a bit rusty so I'm unsure if the syntax is correct, but the general idea should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.