0

I have a query that's retraive a list of id's. Those id's are in an array and i need to save it in table with those id's. I tried using implode to make those id's a string i could use in a where clause but i keep getting this error.

$save_food = $_POST['save_food'];
$unserializedData = array();
parse_str($save_food,$unserializedData);
foreach($unserializedData as $unserializedData1){
$query = mysql_query("insert into subscribefood (s_user_id,s_food) values ('$ft_user_id','".implode($unserializedData1, ',')."')");
}
10
  • 1
    What error's that, then? Commented Oct 5, 2013 at 11:06
  • You are doing something really weird Commented Oct 5, 2013 at 11:06
  • this the error :- Array to string conversion Commented Oct 5, 2013 at 11:38
  • @kamgfx Print your $unserializedData & Show me Commented Oct 5, 2013 at 11:52
  • implode() will give you an array but you need a string. are your sure that you know what you are doing? Commented Oct 5, 2013 at 11:54

1 Answer 1

1

Try this

<?php
$save_food = $_POST['save_food'];
$unserializedData = array();
parse_str($save_food,$unserializedData);
$datalist = $unserializedData['foodtype'];
foreach($datalist as $data){
$query = mysql_query("insert into subscribefood (s_user_id,s_food) values ('$ft_user_id','$data')");
}
?>
Sign up to request clarification or add additional context in comments.

3 Comments

@hek2mgl he needs to insert all 3 values in separate row so only i am using this.
@hek2mgl if you found any wrong please tell me. so only i am update my knowledge.
@NathanSrivi Now, without the implode() it makes sense

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.