0

I want to save the data with php. The program does not return an error. But to the database does not record.

DOSYA ADI:signup.php

MY CODES:

<form action="islem.php" method="post"> 
    Ad:<input type="text" name="bilgilerim_ad" placeholder="giriniz">
    Soyad:<input type="text" name="bilgilerim_soyad" placeholder="giriniz">
    Mail:<input type="text" name="bilgilerim_mail"placeholder="giriniz">
    Yaş:<input type="text" name="bilgilerim_yas" placeholder="giriniz">
    <button name="insertislemi" type="submit">Kayıt</button>
</form>

DOSYA ADI:config.php

MY CODES

<?php
    include 'baglan.php';

    if(isset($_POST['insertislemi'])){

    $query = $db->prepare("INSERT INTO uyeler SET
      bilgilerim_ad =: bilgilerim_ad,
      bilgilerim_soyad =: bilgilerim_soyad,
      bilgilerim_mail =: bilgilerim_mail,
      bilgilerim_yas =: bilgilerim_yas,

    ");
    $insert = $query->execute(array(
        "bilgilerim_ad" => $_POST['bilgilerim_ad'],
        "bilgilerim_soyad" => $_POST['bilgilerim_soyad'],
        "bilgilerim_mail" => $_POST['bilgilerim_mail'],
        "bilgilerim_yas" => $_POST['bilgilerim_yas'],
    ));
    if ( $insert ){
        $last_id = $db->lastInsertId();
        print "insert işlemi başarılı!";
    }

}
?>

MY CODES

CONNECTION FILE

<?php
try {
    $db = new PDO("mysql:host=localhost;dbname=test", "root", "");
    //echo "giriş";
} catch(PDOException $e) {
    echo $e->getMessage();
}

?>
Cid
  • 14,968
  • 4
  • 30
  • 45
Atakan Acar
  • 33
  • 1
  • 11

1 Answers1

2

You first write bilgilerim_ad =: bilgilerim_ad, ... in your insert query, then "bilgilerim_ad" => $_POST['bilgilerim_ad'],.

There's a misplaced space, the datas are bound to bilgilerim_ad but you declared : bilgilerim_ad.

Replace your insert query by :

$query = $db->prepare("INSERT INTO uyeler SET
    bilgilerim_ad = :bilgilerim_ad,
    bilgilerim_soyad = :bilgilerim_soyad,
    bilgilerim_mail = :bilgilerim_mail,
    bilgilerim_yas = :bilgilerim_yas");

And bind your datas this way :

$insert = $query->execute(array(
    ":bilgilerim_ad" => $_POST['bilgilerim_ad'],
    ":bilgilerim_soyad" => $_POST['bilgilerim_soyad'],
    ":bilgilerim_mail" => $_POST['bilgilerim_mail'],
    ":bilgilerim_yas" => $_POST['bilgilerim_yas']));

This is out of topic, but in your php files where you are using only php code (the one that insert and the one that manage DB connection in example) do not close php tag ?>. This can send unwanted characters to http header

Cid
  • 14,968
  • 4
  • 30
  • 45