0

I'm trying make array for emp_no from empregtable and to store array result into another table message (separate rows). I have code something like that. but it is not working. Please if anyone can help me on this, Thanks.

$selectresult = mysqli_query($dbc,"SELECT emp_no FROM empreg"); 
$result_array = array();
while($row = mysqli_fetch_assoc($selectresult))
{
    $result_array[] = $row['emp_no'];
}
$values= serialize($_POST["emp_no"]);
foreach($values as $result)
{
    $sendmessage = mysqli_query ($dbc,"INSERT INTO message (to_user, date,message_title,message_contents) VALUES ('$values', '$date' ,'$subject','$message')");
}
2
  • I don't quite understand what you are doing. You are loading data from empreg into $result_array - but then you aren't using it anywhere. Then you are inserting the entire array from $values into the message table. Surely you meant to use this variable: $result? Commented May 1, 2014 at 9:37
  • hi Latheesan, it is inserting default value i.e (0) instead of array data. Commented May 1, 2014 at 9:39

1 Answer 1

1

You use $values as $result but then don't use $result. Change $values to $result in your foreach.

e.g

    $values= serialize($_POST["custom"]);

    foreach($values as $result)
       {
          $sendmessage = mysqli_query ($dbc,"INSERT INTO message (to_user, date,message_title,message_contents) VALUES ('$result', '$date' ,'$subject','$message')");
       }                                                                                                                   ^---- here
Sign up to request clarification or add additional context in comments.

5 Comments

hi Beat, i did what u told, but no luck. now no value is inserting in my database
Where do $date, $subject and $message come from? @SaurabhMosesRam
i created these variable to store current date, subject and message. subject and message is coming from <input> field and $date = date('Y/m/d H:i:s');
So what is the variable that isn't putting any data in? @SaurabhMosesRam
I have and array $result_array[] = $row['emp_no']; which is taking data from another table empreg. i want to insert array value to another table row i.e message.

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.