Q:

The Function That Adds Twice Records

When i run this function:
function yemek_onay ($id, $session) {
global $db;
global $suAnSaat;
$hasta = $db->query("SELECT * FROM hastalar WHERE id = '{$id}'")->fetch(PDO::FETCH_ASSOC);
$kullanici = sess_info($session);
$ogun = ogun($suAnSaat);
$result = $db->query("INSERT INTO yemek_log SET hasta_id = '{$id}', ogun = '{$ogun}', kullanici_id = '{$kullanici["id"]}'")->execute();
return $result;}

It adds twice record to table. I dont have any idea why it do this.
Table view:

A:

It is because you are running the command twice with a ->query and an ->execute. Each of them will perform the statement once, as you have BOTH it'll run twice. Get rid of either of one of them and it'll work. I'd suggest using a prepared statement, dropping the query and replacing it with the execute version as it'll make it more secure.

