• 17-08-2018, 00:51:05
    #1
    Merhaba arkadaşlar.
    Bir bitirme projesi diyebileceğimiz bir sistem üzerinde çalışıyorum hatta sistem bitti bile sayılır ancak sessions kullanımında bir sorun var gibi görünüyor. Admin giriş yaptığı zaman admin paneline yönlendirme yapılıyor ancak ardından anasayfaya atıyor. Tahminlerime göre session oluşmuyor ve admin sayfası tanıyamadığı için yönlendirmem üzere anasayfaya gönderiyor. Tekrar tekrar kontrol ettim ancak yazımda da bir sorun yok acaba yardımcı olabilir misiniz ?

    Login ve admin sayfaları şu şekilde. Detaylı incelemek isteyen olursa tüm proje dosyalarını da gönderebilirim. Yardımcı olursanız çok sevinirim yüzdüm yüzdüm kuyruğuna geldim.

    login.php
    <div class="alert alert-primary" role="alert">
      Kullanıcı Giriş Ekranı
    </div>
    
    <form action="" method="POST">
    <table>
    <tr>
    <td>Kullanıcı Adı : </td>
    <td><input type="text" name="kullaniciAdi" size="31"></td>
    </tr>
    <tr>
    <td>Şifre : </td>
    <td><input type="text" name="sifre" size="31"></td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" name="btnGiris" value="Giriş Yap" style="width:16em"></td>
    </tr>
    </table>
    </form>
    
    <?php
    ob_start();
    if(isset($_POST["btnGiris"])) {
    @session_start();
    
    $kAdi=$_POST['kullaniciAdi'];
    $pass=md5($_POST['sifre']);
    
    $mysqli = mysqli_connect('localhost', 'root', '', 'kr_vt');
    mysqli_set_charset($mysqli, "utf8");
    $query = "select kullaniciAdi, sifre, statu from login where kullaniciAdi=? and sifre=?";
    $statement = $mysqli->prepare($query);
    $statement->bind_param('ss', $kAdi, $pass);
    $statement->execute();
    $statement->bind_result($kullaniciAdi, $sifre, $statu);
    
    if($statement->fetch()) {
    $_SESSION["login"] = "true";
    $_SESSION["user"] = $kAdi;
    $_SESSION["pass"] = $pass;
    echo '<script>window.location.href="/index.php?sayfa=admin";</script>';
    }
    else {
    echo "<center>Kullanici Adi/Sifre Yanlis.</center>";
    }
    
    $statement->close();
    }
    ob_end_flush();
    ?>
    admin.php
    <div class="row">
    <div class="col-md-3">
    <p>Hoşgeldiniz!
    <?php /*@session_start(); echo $_SESSION["user"];*/ ?>
    </p>
    <p>Admin Menü</p>
    <ul>
    <li><a href="index.php?sayfa=admin&islem=menu">Menü İşlemleri</a></li>
    <li><a href="index.php?sayfa=admin&islem=kategori">Kategori İşlemleri</a></li>
    <li><a href="index.php?sayfa=admin&islem=urun">Ürün İşlemleri</a></li>
    </ul>
    </div>
    <div class="col-md-9">
    <?php
    if(isset($_SESSION["login"])) {
    if(isset($_GET["islem"])) {
    if($_GET["islem"]=="menu") {
    echo '<form action="" method="POST">
    <table>
    <tr>
    <td>Menu Id :</td>
    <td><input type="text" name="menuId" size="31"
    value="'; if(isset($_GET["id"])) echo $_GET["id"]; echo '"></td>
    </tr>
    <tr>
    <td>Menu Adı :</td>
    <td><input type="text" name="menuAdi" size="31"
    value="'; if(isset($_GET["adi"])) echo $_GET["adi"]; echo '"></td>
    </tr>
    <tr>
    <td>Menu Adres :</td>
    <td><input type="text" name="menuAdres" size="31"
    value="'; if(isset($_GET["adres"])) echo $_GET["adres"]; echo '"></td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" name="btnMenuKaydet" value="Menü Kaydet" style="width:16em"></td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" name="btnMenuGuncelle" value="Menü Güncelle" style="width:16em"></td>
    </tr>
    </table>
    </form>';
    
    $mysqli = mysqli_connect('localhost', 'root', '', 'kr_vt');
    mysqli_set_charset($mysqli, "utf8");
    $query = "select menuId,menuAdi, menuAdres from menu order by menuId desc";
    $statement = $mysqli->prepare($query);
    $statement->execute();
    $statement->bind_result($menuId,$menuAdi, $menuAdres);
    
    echo "<br><table border='1'><tr>
    <td></td>
    <td></td>
    <td>Menu Id</td>
    <td>Menu Adı</td>
    <td>Menu Adres</td>
    </tr>";
    while($statement->fetch()) {
    echo '<tr>
    <td><a href="index.php?sayfa=admin&islem=menuSil&id='.$menuId.'">Sil</a></td>
    <td><a href="index.php?sayfa=admin&islem=menu&id='.$menuId.'&adi='.$menuAdi.'">Güncelle</a></td>
    <td>'.$menuId.'</td>
    <td>'.$menuAdi.'</td>
    <td>'.$menuAdres.'</td>
    </tr>';
    }
    echo "</table>";
    
    $statement->close();
    
    if(isset($_POST["btnMenuKaydet"])) {
    $param1=$_POST["menuAdi"];
    $param2=$_POST["menuAdres"];
    
    $query = "insert into menu (menuAdi,menuAdres) values (?,?)";
    $statement = $mysqli->prepare($query);
    $statement->bind_param('ss', $param1, $param2);
    $statement->execute();
    $statement->close();
    echo '<script>window.location.href="/index.php?sayfa=admin&islem=menu";</script>';
    }
    if(isset($_POST["btnMenuGuncelle"])) {
    $param1=$_POST["menuAdi"];
    $param2=$_POST["menuAdres"];
    $param3=$_POST["menuId"];
    
    $query = "update menu set menuAdi=?, menuAdres=? where menuId=?";
    $statement = $mysqli->prepare($query);
    $statement->bind_param('ssi', $param1, $param2, $param3);
    $statement->execute();
    $statement->close();
    echo '<script>window.location.href="/index.php?sayfa=admin&islem=menu";</script>';
    }
    }
    else if ($_GET["islem"]=="menuSil") {
    $deger =$_GET["id"];
    $query = "delete from menu where menuId=?";
    $statement = $mysqli->prepare($query);
    $statement->bind_param('i', $deger);
    $statement->execute();
    $statement->close();
    echo '<script>window.location.href="/index.php?sayfa=admin&islem=menu";</script>';
    }
    else if($_GET["islem"]=="kategori") {
    echo '<form action="" method="POST" enctype="multipart/form-data">
    <table>
    <tr>
    <td>Kategori Id :</td>
    <td><input type="text" name="kategoriId" size="31"
    value="'; if(isset($_GET["id"])) echo $_GET["id"]; echo '"></td>
    </tr>
    <tr>
    <td>Kategori Adı :</td>
    <td><input type="text" name="kategoriAdi" size="31"
    value="'; if(isset($_GET["adi"])) echo $_GET["adi"]; echo '"></td>
    </tr>
    <tr>
    <td>Kategori Resim :</td>
    <td><input type="file" name="kategoriResim" size="31"></td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" name="btnKategoriKaydet" value="Kategori Kaydet" style="width:16em"></td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" name="btnKategoriGuncelle" value="Kategori Güncelle" style="width:16em"></td>
    </tr>
    </table>
    </form>';
    
    $mysqli = mysqli_connect('localhost', 'root', '', 'kr_vt');
    mysqli_set_charset($mysqli, "utf8");
    $query = "select kategoriId,kategoriAdi,kategoriResim from kategori order by kategoriid desc";
    $statement = $mysqli->prepare($query);
    $statement->execute();
    $statement->bind_result($kategoriId,$kategoriAdi,$kategoriResim);
    
    echo "<br><table border='1'><tr>
    <td></td>
    <td></td>
    <td>Kategori Id</td>
    <td>Kategori Adı</td>
    <td>Kategori Resim</td>
    </tr>";
    while($statement->fetch()) {
    echo '<tr>
    <td><a href="index.php?sayfa=admin&islem=kategoriSil&id='.$kategoriId.'">Sil</a></td>
    <td><a href="index.php?sayfa=admin&islem=kategori&id='.$kategoriId.'&adi='.$kategoriAdi.'">Güncelle</a></td>
    <td>'.$kategoriId.'</td>
    <td>'.$kategoriAdi.'</td>
    <td><img src="./images/kategori/'.$kategoriResim.'" width="100"/></td>
    </tr>';
    }
    echo "</table>";
    
    $statement->close();
    
    if(isset($_POST["btnKategoriKaydet"])) {
    $param1=$_POST["kategoriAdi"];
    
    $dizin = './images/kategori/';
    $yuklenecek_dosya = $dizin . basename($_FILES['kategoriResim']['name']);
    
    if (move_uploaded_file($_FILES['kategoriResim']['tmp_name'], $yuklenecek_dosya))
    {
    $param2=basename($_FILES['kategoriResim']['name']);
    
    $query = "insert into kategori (kategoriAdi, kategoriResim) values (?,?)";
    $statement = $mysqli->prepare($query);
    $statement->bind_param('ss', $param1, $param2);
    $statement->execute();
    $statement->close();
    echo '<script>window.location.href=/index.php?sayfa=admin&islem=kategori";</script>';
    } else {
    echo "Resimde Yükelemede Hata!";
    }
    }
    else if(isset($_POST["btnKategoriGuncelle"])) {
    $param1=$_POST["kategoriAdi"];
    $param2=$_POST["kategoriId"];
    
    $query = "update kategori set kategoriAdi=? where kategoriId=?";
    $statement = $mysqli->prepare($query);
    $statement->bind_param('si', $param1, $param2);
    $statement->execute();
    $statement->close();
    echo '<script>window.location.href=/index.php?sayfa=admin&islem=kategori";</script>';
    }
    }
    else if ($_GET["islem"]=="kategoriSil") {
    $deger =$_GET["id"];
    $query = "delete from kategori where kategoriId=?";
    $statement = $mysqli->prepare($query);
    $statement->bind_param('i', $deger);
    $statement->execute();
    $statement->close();
    
    $query = "select kategoriId,kategoriAdi,kategoriResim from kategori where kategoriId=?";
    $statement = $mysqli->prepare($query);
    $statement->bind_param('i', $deger);
    $statement->execute();
    $statement->bind_result($kategoriid,$kategoriAdi,$kategoriResim);
    $statement->fetch();
    $dosya = "./images/kategori/" . $kategoriResim;
    unlink($dosya);
    $statement->close();
    echo '<script>window.location.href=/index.php?sayfa=admin&islem=kategori";</script>';
    }
    else if($_GET["islem"]=="urun") {
    echo '<form action="" method="POST" enctype="multipart/form-data">
    <table>
    <tr>
    <td>Ürün Id :</td>
    <td><input type="text" name="urunId" size="31"
    value="'; if(isset($_GET["id"])) echo $_GET["id"]; echo '"></td>
    </tr>
    <tr>
    <td>Ürün Kodu :</td>
    <td><input type="text" name="urunKodu" size="31"
    value="'; if(isset($_GET["kodu"])) echo $_GET["kodu"]; echo '"></td>
    </tr>
    <tr>
    <td>Ürün Resim :</td>
    <td><input type="file" name="urunResim" size="31"></td>
    </tr>
    <tr>
    <td>Ürün Kategori :</td>
    <td>
    <select name="kategoriId">';
    $mysqli = mysqli_connect('localhost', 'root', '', 'kr_vt');
    mysqli_set_charset($mysqli, "utf8");
    $query = "select kategoriId, kategoriAdi from kategori";
    $statement = $mysqli->prepare($query);
    $statement->execute();
    $statement->bind_result($kategoriId, $kategoriAdi);
    
    while($statement->fetch()) {
    if(isset($_GET["kategori"])) {
    if($_GET["kategori"]==$kategoriId) {
    echo '<option value="'.$kategoriId.'" selected>'.$kategoriAdi.'</option>';
    }
    else {
    echo '<option value="'.$kategoriId.'">'.$kategoriAdi.'</option>';
    }
    }
    else {
    echo '<option value="'.$kategoriId.'">'.$kategoriAdi.'</option>';
    }
    }
    
    $statement->close();
    echo '</select>
    </td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" name="btnUrunKaydet" value="Ürün Kaydet" style="width:16em"></td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" name="btnUrunGuncelle" value="Ürün Güncelle" style="width:16em"></td>
    </tr>
    </table>
    </form>';
    
    $mysqli = mysqli_connect('localhost', 'root', '', 'kr_vt');
    mysqli_set_charset($mysqli, "utf8");
    $query = "select u.urunId,u.urunKodu,u.urunResim,u.kategoriId,k.kategoriAdi
    from urun u, kategori k where u.kategoriId=k.kategoriId order by urunid desc";
    $statement = $mysqli->prepare($query);
    $statement->execute();
    $statement->bind_result($urunId,$urunKodu,$urunResim,$kategoriId,$kategoriAdi);
    
    echo "<br><table border='1'><tr>
    <td></td>
    <td></td>
    <td>Ürün Id</td>
    <td>Ürün Kodu</td>
    <td>Ürün Resim</td>
    <td>Ürün Kategori</td>
    </tr>";
    while($statement->fetch()) {
    echo '<tr>
    <td><a href="index.php?sayfa=admin&islem=urunSil&id='.$urunId.'">Sil</a></td>
    <td><a href="index.php?sayfa=admin&islem=urun&id='.$urunId.'&kodu='.$urunKodu.'&kategori='.$kategoriId.'">Güncelle</a></td>
    <td>'.$urunId.'</td>
    <td>'.$urunKodu.'</td>
    <td><img src="./images/urun/'.$urunResim.'" width="100"/></td>
    <td>'.$kategoriAdi.'</td>
    </tr>';
    }
    echo "</table>";
    
    $statement->close();
    
    if(isset($_POST["btnUrunKaydet"])) {
    $param1=$_POST["urunKodu"];
    $param3=$_POST["kategoriId"];
    
    $dizin = './images/urun/';
    $yuklenecek_dosya = $dizin . basename($_FILES['urunResim']['name']);
    
    if (move_uploaded_file($_FILES['urunResim']['tmp_name'], $yuklenecek_dosya))
    {
    $param2=basename($_FILES['urunResim']['name']);
    
    $query = "insert into urun (urunKodu, urunResim, kategoriId) values (?,?,?)";
    $statement = $mysqli->prepare($query);
    $statement->bind_param('ssi', $param1, $param2, $param3);
    $statement->execute();
    $statement->close();
    echo '<script>window.location.href=/index.php?sayfa=admin&islem=urun";</script>';
    } else {
    echo "Resimde Yükelemede Hata!";
    }
    }
    else if(isset($_POST["btnUrunGuncelle"])) {
    $param1=$_POST["urunKodu"];
    $param2=$_POST["kategoriId"];
    $param3=$_POST["urunId"];
    
    $query = "update urun set urunKodu=?,kategoriId=? where urunId=?";
    $statement = $mysqli->prepare($query);
    $statement->bind_param('sii', $param1, $param2, $param3);
    $statement->execute();
    $statement->close();
    echo '<script>window.location.href=/index.php?sayfa=admin&islem=urun";</script>';
    }
    }
    else if ($_GET["islem"]=="urunSil") {
    $deger =$_GET["id"];
    $query = "delete from urun where urunId=?";
    $statement = $mysqli->prepare($query);
    $statement->bind_param('i', $deger);
    $statement->execute();
    $statement->close();
    
    $query = "select urunId,urunKodu,urunResim from urun where urunId=?";
    $statement = $mysqli->prepare($query);
    $statement->bind_param('i', $deger);
    $statement->execute();
    $statement->bind_result($urunId,$urunKodu,$urunResim);
    $statement->fetch();
    $dosya = "./images/urun/" . $urunResim;
    unlink($dosya);
    $statement->close();
    echo '<script>window.location.href=/index.php?sayfa=admin&islem=urun";</script>';
    }
    }
    }
    else {
    echo '<script>window.location.href=/index.php";</script>';
    }
    ?>
    </div>
    </div>
  • 17-08-2018, 00:56:06
    #2
    $statement->bind_param('ss', $kAdi, $pass);
    burada ss değeri neyi temsil etmekte? Sorguda 2 veri gözükürken bind_param da 3 veri var
  • 17-08-2018, 02:10:24
    #3
    <?php
    session_start();

    şeklinde sayfa başında kullanınız.
  • 17-08-2018, 08:54:01
    #4
    ismail03 adlı üyeden alıntı: mesajı görüntüle
    $statement->bind_param('ss', $kAdi, $pass);
    burada ss değeri neyi temsil etmekte? Sorguda 2 veri gözükürken bind_param da 3 veri var
    Durumu nasıl çözebilirim hocam. ss değerini Silmem mi gerekiyor ?

    Ceu adlı üyeden alıntı: mesajı görüntüle
    <?php
    session_start();

    şeklinde sayfa başında kullanınız.
    Teşekkür ederim hocam akşam projeye uygulayıp deniyorum.