Why no data is written to the database?

In short, guys. There is code:
for($i = 0; $i < count($groups); $i++){
 /* $find = mysql_query("SELECT * FROM groups_data WHERE group_id=".$groups[$i]);
 $find = mysql_fetch_assoc($find);
if(empty($find['group_id'])){
 mysql_query("INSERT INTO groups_data (group_id,post_id) VALUES (".$groups[$i].",0)") or die(mysql_error()); //add our group to the database, post_id setting default 0
 } else {*/
 $wallGet = api("https://api.vk.com/method/wall.get?owner_id=-".$groups[$i]."&count=1");
 $wallGet = json_decode($wallGet);
 $id = $wallGet->response[1]->id.' ';
 $group = $groups[$i];


 $res = mysql_query("UPDATE groups_data SET `post_id`='".$id[$i]."' WHERE `group_id`='".$groups[$i]."';");
 echo $res.'<br>';
 # }


}

He somehow writes data only to the first group_id, and then - no, what to do?
in $groups is:
$groups = array('122860616','122860645','122860660');
July 8th 19 at 16:04
2 answers
July 8th 19 at 16:06
Solution
One I can see that the query with the insert salmeterolo? Run only update.
The code before "else" is not as important in this situation, put it here only for completeness. - Sylvia_Harris42 commented on July 8th 19 at 16:09
: Make it so
$res_sql = "UPDATE groups_data SET `post_id`='".$id[$i]."' WHERE `group_id`='".$groups[$i]."';";
$res = mysql_query($res_sql);
echo $res.'
'; - dalton_Mora commented on July 8th 19 at 16:12
that worked, thanks. - Sylvia_Harris42 commented on July 8th 19 at 16:15
: there was not output sql script, and the result of mysql_query, which was most likely to fail. The author brought to the screen the script and saw the error. - dalton_Mora commented on July 8th 19 at 16:18
I don't know, but it worked:) - Sylvia_Harris42 commented on July 8th 19 at 16:21
July 8th 19 at 16:08
Ooh, this porridge to stew, not my watch! (C) Jar Jar Binks.
1) the Mess though, but Oh well, it's half the trouble.
2) Use prepared statements and PDO.
3) Create queries in variables, then pass the request for execution, so at least you can debugging that there the request goes.
4) If anything not clear(as here) - in line put print_r(), and so for everything that moves.
5) Profit
What I PDO? The script uses a narrow circle of people. (1-2 people) - Sylvia_Harris42 commented on July 8th 19 at 16:11
: is this a criterion to do/not to do? First is a modern, second mysql functions deprecated, thirdly, you asked for advice from people you suggest, there is debugging normal, and tomorrow work will not cease. And besides - all the rest do, no you do not impose the same. Most likely how it will perform find your bug for a couple of minutes. - dalton_Mora commented on July 8th 19 at 16:14
: will do someday. :) - Sylvia_Harris42 commented on July 8th 19 at 16:17

Find more questions by tags MySQLPHP