Navigation Menu



PHP BLOG - somo la 12: Jinsi ya kutumia prepared statement kwenye kusoma post za blog

Katika somo hili tutakwenda kutumia prepared ststement kwenye ku fetch data kutoka kwenye database.

Somo hili ni muendelezo wa masomo mawili yaliotangulia nyuma. Hvyo basi hapa nitakwenda kukuletea orodha ya mabadliko ya mafaili yote yaliobadilishwa baada ya kutumia prepared statement.

Pia tutakwenda kutatuwa tatizo la kufuta pica. Hapa tutakwenda kutatua liletatizo unapo edit icha le ya zamani inabakia. 

Ili kuelewa vyema somo hili tafadhali rejea mazomo mawili yaliotangulia kwa njia ya video. Tembelea channel yetu ya youtube inayopatikana kwa link hii youtube.com/@tehama-tz

 

dashboard.php

<html>
<head>
<title>Dshboard</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
table, th, td {
border:1px solid black;
}
.dol{
margin: 0 auto;
max-width: 70%;
}
</style>
</head>
<body>
<h1><a href="post.php">Ongeza post</a> </h1>
<table>
<tbody>
<th>id</th>
<th>Image</th>
<th>Title</th>
<th>Publshed</th>
<th>Updated</th>
<th>Publsher</th>
<th>Soma</th>
<th>edit</th>
<th>Delete</th>
<?php
include "config.php";
$sql= $conn->prepare("SELECT * FROM posts");
$sql->execute();
$result = $sql->get_result();
while ($post = $result->fetch_assoc()){?>
<tr>
<td><?php echo $post['id']?></td>
<td><img src="upload/<?php echo $post['image']?>" height="5%" width="5%"></td>
<td><?php echo $post['title']?></td>
<td><?php echo $post['post_time']?></td>
<td><?php echo $post['updated_time']?></td>
<td><?php echo $post['publisher']?></td>
<td><a href="view.php?id=<?php echo $post['id']?>">Soma</a> </td>
<td><a href="edit.php?id=<?php echo $post['id']?>">edit</a> </td>
<td><a href="delete.php?id=<?php echo $post['id']?>">Futa</a> </td>
</tr>
<?php }?>
</tbody>
</table>
</body>
</html>

 

 

delete.php

 

$id = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT);

include "config.php";

$sql= $conn->prepare("SELECT image FROM posts where id =?");

$sql->bind_param("i", $id);

$sql->execute();

$result = $sql->get_result();

while ($post = $result->fetch_assoc()){

$image = $post['image'];

unlink("upload/".$image);

$sql= $conn->prepare("DELETE FROM posts where id =?");

$sql->bind_param("i", $id);

$sql->execute();

header("location:dashboard.php");



}

 

 

 

 

 

 

post.php

<html>
<head>
<title>create your post</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.ckeditor.com/4.16.2/standard/ckeditor.js"></script>
<script src="ckeditor.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<label for="title">Title</label><br>
<input type="text" name="title" placeholder="write your post title" id="title"><br>

<label for="summary">Summary</label><br>
<input type="text" name="summary" placeholder="write your post summary" id="summary"><br>

<label for="content">content</label><br>
<textarea name="content" id="content" placeholder="wrte your post content"></textarea>
<script>CKEDITOR.replace( 'content' );
</script>
<label for="publisher">publisher</label><br>
<input type="text" name="publisher" placeholder="write your post publisher" id="publisher"><br>

<label for="date">Date</label><br>
<input type="date" name="date" placeholder="write your post date" id="date"><br><br>

<label for="image">upload your image</label>
<input type="file" name="file" accept="image/*" id="image"><br><br>

<input type="submit" name="submit" value="submit">
</form>
<br><br>
</body>
</html>
<?php
include "config.php";
if (isset($_POST['submit'])) {
//start code
// form variables
$title = filter_var($_POST['title'], FILTER_SANITIZE_STRING);
$summary = filter_var($_POST['summary'], FILTER_SANITIZE_STRING);
$content = $_POST['content'];
$publish">...

Download app yetu

Jifunze zaidi, na wasiliana nasi ukiw ana App yetu. Bofya liln hapo chini kuweza ku download

Download Now Bongoclass

           

Je! umeipenda hii post?
Ndio            Hapana            Save post

Rajabu image Tarehe 2024-05-10 14:53:23 Topic: PHP Main: Project File: Download PDF     Share On Facebook or Whatsapp Views 1461


Sponsored links
👉1 Sira ya Mtume Muhammad (s.a.w)     👉2 Kitau cha Fiqh     👉3 Madrasa kiganjani     👉4 Simulizi za Hadithi Audio     👉5 Kitabu cha Afya     👉6 kitabu cha Simulizi    

Post zifazofanana:-

PHP somo la 66: Jinsi ya ku edit data na kufuta kwenye database kwa kutumia PDO
Katika somo hili utakwenda kujifunza jinsi jinsi ya ku edit ama ku update data na kuzifuta kwenye database kwa kutumia PDO Soma Zaidi...

PHP somo la 54: class constant kwenye php
Katika somo hili utakwenda kujifunza jinsi ya kutumia constatnt kwenye class. Soma Zaidi...

PHP - somo la 38: Jinsi ya ku upload mafaili zaidi ya moja kwa kutumia PHP
katika somo hili utajifunza jinsi ya ku upload multiple file yaani mafaili mengi kwa wakati mmoja kwa kutumia PHP Soma Zaidi...

PHP - somo la 26: Jinsi ya kutengeneza system ya ku chat kw akutumia PHP
Katika somo hili utajifunza jinsi ya kutengeneza system ambayo mta atajisajili pamoja na kuchat na watumiaji wengine Soma Zaidi...

PHP - somo la 47: Jifunze kuhusu sql injection na kuizuia
Katika somo hili utajwenda kujifunza jinsi ya kuzuia hacking kwenye website yako Soma Zaidi...

PHP somo la 82: Content-Disposition
Katika somo hili utakwenda kujifunza kuhusu aina ya header inayoitwa Content-Disposition Soma Zaidi...

PHP BLOG - somo la 9: Jinsi ya ku edit poost
Katika somo hil utawenda kujifunza jinsi ya ku edit post kwenye databse Soma Zaidi...

PHP - somo la 13: Jinsi ya kuunganisha database na website
Katika somo hili utajifunza jinsi ya ku connect database, kwa kutumia php Soma Zaidi...

PHP somo la 84: Maana ya JSON na sheria za kuandika faili la json
Katika somo hili utakwenda kujifunza kuhusu Maana ya JSON na sheria za kuandika faili la json Soma Zaidi...

PHP somo la 89: Jinsi ya kutumia data za json kwenye program ya php na html
Katika somo hili utakwend akujifunza ni kwa namna gani utaweza kuzitumiadata za jsonkwenye program yako Soma Zaidi...