There are no errors, but the addition does not happen for some reason. Just writes that "id does not exist." Can someone tell me how to fix it?

if (isset($userInfo['response'][0]['id'])) { $userInfo = $userInfo['response'][0]; $result = mysqli_query($mysqli, "SELECT * FROM users WHERE id = ". $userInfo['id'] .""); $cols = mysqli_num_rows($result); if($cols == 0) { echo 'id не существует'; mysqli_query($mysqli, "INSERT INTO users ('id', 'first_name', 'last_name', 'photo_50') VALUES ({$userInfo['id']}, {$userInfo['first_name']}, {$userInfo['last_name']}, {$userInfo['photo_50']})"); } else { echo 'id существует'; } } 

enter image description here

All necessary data is coming, the array is not empty.

 array(4) { ["id"]=> int(122238003) ["first_name"]=> string(12) "Родион" ["last_name"]=> string(14) "Поляков" ["photo_50"]=> string(54) "http://cs628825.vk.me/v628825003/3f340/jHKzi1BNezk.jpg" } 
  • $result = mysqli_query($mysqli, "INSERT INTO users ('id', 'first_name', 'last_name', 'photo_50') VALUES ({$userInfo['id']}, {$userInfo['first_name']}, {$userInfo['last_name']}, {$userInfo['photo_50']})"); var_dump($result); what does? - Naumov
  • It is clear that if the record is not saved, then false is output. Find out what the error comes from mysql, Check if your Id is duplicated, it’s not clear why you didn’t auto-make it. If this is not the case, then var_dump(mysqli_errno($mysqli));exit; - Daniel-664
  • @Naumov displays false: ssmaker.ru/09f2b4b0.jpg - Rodion Polyakov
  • @ Daniel-664 autoincrement is not needed, since it is the uid from vk and it is unique anyway. - Rodion Polyakov
  • You have forgotten quotes in the request as you write text data - Naumov

1 answer 1

Try instead of curly braces around a variable to use a quote and a bracket (something like $var['one'] )