Samer El Gendy
Samer El Gendy

Reputation: 1683

taking the values in checkBox and insert it to mysql database

I am trying to create a php function where user can check on a list of people to send them messages, however it seems like something wrong with getting the values in an array and inserting them into database one by one. here's by code:

$message=$_POST['body'];
  $x = $_POST['authors'];
  if( isset($x  ) && is_array($x)) {
      $fulexp = implode(",", $x);
foreach ($x as $item) 
   {
    $fulexp = implode(",", $x);
    $var = intval($item);    
    mysql_select_db('mydb');
    $re =  mysql_query("INSERT INTO member_message_member (member_id1, member_id2,conference_id, message)
                    VALUES (6, $var, 1,  $message)");

     if (!$re) {echo "ya a7maaaad";}
   }   
}
else {echo "enta mush msyttar";}
mysql_close($con);
} 

when i submit the message, nothing inserted into database. anyone can help?

Upvotes: 1

Views: 446

Answers (1)

sarwar026
sarwar026

Reputation: 3821

Please try with

mysql_select_db('mydb', $link);

where, $link should be defined as below:

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');

Also, the line

$fulexp = implode(",", $x);  

in for loop is redundant may be.

Upvotes: 2

Related Questions