Forum Moderators: coopster
$payment_means=array();// array initialization.
$payment_means=mysqli_real_escape_string($connection, strip_tags(trim($_POST['payment_means'])));// of course in the HTML, all checkboxes have same name "payment_means[]"
$payment_means=implode(',', $payment_means);
// check if payment means is array
if(!is_array($payment_means)) $payment_means=explode(',', $payment_means); // this is in case for example the user clicks only one checkbox. The second array value would be an empty string, but empty string is allowed in database, so no problem at that level.
// check values to be sent to database.
if(!isset($date) ¦¦ !isset($expense_amount) ¦¦ !isset($expense_reason) ¦¦ !isset($location) ¦¦ !isset($payment_means))
{
echo "<pre>You didn't fill in all the fields</pre>";
exit();
}
When I run the whole script I get an "Array to string conversion" notice just from the second line of the script above like this:
"Notice: Array to string conversion in C:\htdocs\MySQL_queries\expense_checkbox.php on line 17
Warning: implode() [function.implode]: Bad arguments. in C:\htdocs\MySQL_queries\expense_checkbox.php on line 18
Query failed!"
Any idea of how to solve this? I am thinking of a way of assigning the values into the array so that no conversion is needed just in the way $payment_means would be = array("value1", "value2",..., "value N"); I think this way would give no warning for the implode() function as shown above.
Please take one minute to let me know what I should do.
Regards,