php - Correct usage of array values in WHERE clause -


i attempting set reply notification application using php. when site visitor fills out reply form on website , hash-tags other participants in discussion (#mike, #wale ), application extracts hash-tags , uses preg_match_all() function process , extract usernames hash-tags , then, stored in array.

based on values in username array, application supposed iterate through users table in database, extracting email addresses match username , thereafter each user sent reply notification.

the part of application should execute select query throwing error, have highlighted below: warning: mysqli_error() expects 1 parameter, 0 given in c:\wamp\www\lost_and_found\send_reply_notification.php on line 33.

take @ code below:

 <?php  ///////////////////extract matches array//////////////////////////  $data = "#mike party start @ 10:30 pm , #john1975 run untill 12:30 am. please #emeka, inform #joseph?";  preg_match_all('/#[a-z0-9]+/i', $data, $match, preg_pattern_order); $usernames=$match[0] ;  /////////////convert array string using implode/////////////////// $newlist = implode( ",", $usernames );  $count = count($newlist); /////////////////store username array/////////// ($i = 0; $i < $count; $i++) {   preg_match_all('/#[a-z0-9]+/i', $newlist, $match, preg_pattern_order);  $full_name=$match[0];}  ////////////////////////extract usernames/email pair database//////////////// ($i = 0; $i < $count; $i++)     //dabase connection script     $sql = 'select * users username='. $full_name[$i];     // submit query , capture result     $result = $conn->query($sql) or die(mysqli_error());     if ($result)          {             //send mail query here.         }    ?>  

it appears clause in select query not accepting '$full_name[$i]' value input.

how may resolve this, iterate through users table using values in array in clause?

thanks.

add quotes name in query like

$sql = 'select * users username="'. $full_name[$i].'"'; 

and don't forgot put code inside { } in for loop.

for ($i = 0; $i < $count; $i++) {     //dabase connection script     $sql = 'select * users username="'. $full_name[$i].'"';     // submit query , capture result     $result = $conn->query($sql) or die(mysqli_error());     if ($result)          {             //send mail query here.         }  } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -