Reputation: 31
I really dont understand where is the mistake. I have a database named giderler. And it includes id(Primary key),kisi (varchar), tur (varchar), fiyat (varchar), mal(varchar), tarih (datetime), hesap (int). And I just want to add some records to table. I'm looking for an one hour on the internet, but i cant find anything, any answer.
Here is the codes:
if(isset($_POST['AddExpense'])){
/* Formdan gerekli veiler alınıyor */
$kisi = $_POST['kisi'];
$tur = $_POST['tur'];
$fiyat = $_POST['fiyat'];
$mal = $_POST['mal'];
if(!is_numeric($fiyat))
{
/* Fiyat sadece integer değer alıyor. */
echo '<div id="error">Lütfen Fiyatı Sadece Rakam Olarak Giriniz!</div>';
die;
}
$tarih = date("d-m-Y 00:00:00"); /* Tarih formatı gg-aa-yy */
echo $kisi. ' - ' .$tur. ' - ' .$mal. ' - ' .$fiyat. ' - '. $tarih;
/* Veritabanına kayıt gerçekleştiriliyor */
try{
$add_expense = $db->prepare("INSERT INTO giderler (kisi,tur,mal,fiyat,tarih,hesap) VALUES (:kisi,:tur,:mal,:fiyat,:tarih,:hesap");
$add_expense->execute(array(
':kisi' => $kisi,
':tur' => $tur,
':mal' => $mal,
':fiyat' => $fiyat,
':tarih' => $tarih,
':hesap' => 0 /* Yeni girilen kayıt. Ödeşmeler gerçekleşmedi. Bu değer ay sonunda 1 olacak */
));
echo '<div id="successs">Sayın '.$kisi.', Kaydınız Başarıyla Eklendi.</div>';
/*Exception fırlatılıyor*/
}catch(PDOException $ex){
echo 'Error: '.$ex->getMessage();
}
}
Here is the exception:
Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Upvotes: 0
Views: 350
Reputation: 204784
You are missing a )
at the end
$db->prepare("INSERT INTO giderler (kisi,tur,mal,fiyat,tarih,hesap)
VALUES (:kisi,:tur,:mal,:fiyat,:tarih,:hesap");
^-------here
Upvotes: 1