Click here to Skip to main content
15,904,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am able to save some records to db but I cant display them.What am i doing wrong here

this part rewtries an empty array

<?php

$cek = $baglanti->db->prepare('select * form defter');
$cek->execute();
$sorgu = $cek->fetchAll(PDO::FETCH_ASSOC);
if (count($sorgu) != 0) {
    foreach ($sorgu as $key => $value) {
        echo $value['mesaj'];
    }
}

?>


What I have tried:

<?php

require_once 'baglanti.php';
$baglanti = new baglanti();

?>

<?php


if ($_POST) {
    $ad = strip_tags($_POST['ad']);
    $soyad = strip_tags($_POST['soyad']);
    $email = strip_tags($_POST['email']);
    $mesaj = strip_tags($_POST['mesaj']);

    $sorgu = $baglanti->db->prepare('Insert into defter (ad,soyad,email,mesaj) values(?,?,?,?)');
    $calistir = $sorgu->execute([$ad, $soyad, $email, $mesaj]);
    if ($calistir) {
        echo 'yazdınız';
    } else {
        echo 'hata';
    }
}

?>



<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
  
</head>

<body>
    <form action="" method="post">
    
    <div class="form">
    <span>İsim</span>
    <input type="text" name="ad">
    </div>

    <div class="form">
    <span>Soyad</span>
    <input type="text" name="soyad">
    </div>

    <div class="form">
    <span>Email</span>
    <input type="text" name="email">
    </div>
    

    <div class="form">
    <span>Mesaj</span>
   <textarea name="mesaj" id="" cols="30" rows="10"></textarea>
    </div>


<button>Gonder</button>

    </form> 
</body>
</html>


<?php

$cek = $baglanti->db->prepare('select * form defter');
$cek->execute();
$sorgu = $cek->fetchAll(PDO::FETCH_ASSOC);
if (count($sorgu) != 0) {
    foreach ($sorgu as $key => $value) {
        echo $value['mesaj'];
    }
}

?>
Posted
Comments
MadMyche 26-Dec-18 23:02pm    
Any errors thrown from this? select * form defter
ChauhanAjay 27-Dec-18 0:34am    
Correct your query from "select * form defter" to "select * from defter" and check

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900