image

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'];
$publisher = ">...



Kama unahitaji kuuliza maswali Bofya hapa





           

Je! umeipenda hii post?
Ndio            Hapana            Save post

Rajabu Tarehe 2024-05-10 14:53:23 Download PDF     Share On Facebook or Whatsapp Imesomwa mara 393


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

Post zifazofanana:-

PHP somo la 56:class interface na polymorphism kwenye PHP OOP
Katika somo hili utakwenda kujifunza concept ya interface na concept ya polymorphism kwenye PHP OOP. Soma Zaidi...

PHP somola 69: jinsi ya kutuma email kwa watu zaidi ya mmoja kwa kutumia PHPMailer
Katika somo il utajifunza kutuma email kwa watu wengi kwa kutumia PHPMailer. Pia utajifunza jinsi ya kuweka Carbon Copy na Blind Carbon Copy Soma Zaidi...

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

PHP somol la 55: PHP Abstract Class na abstract method
Katika somo hili utakwenda kujifunza concept mpya ya abstract class na abstract method kwenye OOP. Soma Zaidi...

PHP - somo la 39: Jinsi ya kutengeneza mafaili na mafolda kwenye server kwa kutumia PHP
Katika somo hili utakwenda kujifunza jinsi ya kuzungumza na server ili kutengeneza mafaili, mafolda, kufuta na ku edit kwa kutumia PHP. Soma Zaidi...

PHP - somo la 34: Jinsi ya kutumia do loop, while loop na foreach kwenye PHP
Katika somo hili utakwenda kujifunza kuhusu aina za loop DO, FOR, FOREACH LOOPS kwenye PHP Soma Zaidi...

PHP somo la 53: class inheritance kwenye PHP Object Oriented Programming
Katika somo hili utakwenda kujifunza kuhusu class inheritance kwenye object oriented programming. Soma Zaidi...

PHP somola 78: Cookie Headers
Katika somo hili utakwenda kujifunza kuhusu Cookie Headers Soma Zaidi...

PHP somo la 52: Aina za access modifire na zinavyotofautiana.
Katika somo hili utakwenda kujifunza kuhusu access modifier ili kuweza kuthibiti nama ya kuzitumia properties kwenye class. Soma Zaidi...

PHP - somo la 24: Jinsi ya ku upload file kwenye database na kulisoma kw akutumia php
Katika somo hili utajifnza jinsi ya ku upload file kwenye database. Kisha utajifunza jinsi ya kulisoma faili hilo 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 86: JInsi ya ku decode json yaani kubadili json kuwa php data kama array ana object
Katika somo hili utakwend akujifunza jinsi ya kubadili json data na kuwaphp array ama php object. Kwa ufupi tunakwend aku decode json data kuwa phparray amaobject Soma Zaidi...