Navigation Menu



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



Nicheki WhatsApp kwa maswali





           

Je! umeipenda hii post?
Ndio            Hapana            Save post

Rajabu Tarehe 2024-05-10 14:53:23 Topic: PHP Main: Project File: Download PDF     Share On Facebook or Whatsapp Imesomwa mara 1402


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

Post zifazofanana:-

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 12: Jinsi ya kufanyia kazi taarifa zilizokusanywa kutoka kwa mtumiaji
Katika somo hili utakwenda kujifunza jinsi ya kutumia taarifa ambazo zimekusanywa kutoka kwa mtumiaji ili kuweka kutatuwa hoja mbalimbali Soma Zaidi...

PHP somola 63: Jinsi ya ku connect database kwa kutumia PDO na faida zake
Katika soo hili utakwenda kujifunza umuhmu wa kutumia PDO kwenye PHP kwa ajili ya kutumia database. Soma Zaidi...

PHP somo la 88: Jisnsi ya kutengeneza json data kutoka kwenye database
Katika somo ili utakwenda kujifunz ahatuwa kwa hatuwa jinsi ya kutengeneza json data kutkana na data ambazo zio kwenye database Soma Zaidi...

PHP BLOG - somo la 8: Jinsi ya kufuta post kwenye database
katika post hii utajifunza jinsi ya kufuta post kwenye database. pia utajifunza jinsi ya kufuta picha kwenye server Soma Zaidi...

PHP -somo la 31: Matumizi ya include() na require() function kwenye php
Katika somo hili utakwenda kujifunza jinsi ya kuandika function za PHP kama require() na iclude() Soma Zaidi...

PHP somo la 74: aina za http headerna server variable
Katika somo hii utakwenda kujifunza aina za http header na server variable. Hapa tutakwenda kuchambuwa mgawanyiko wa httpheader na kazi zake. Soma Zaidi...

PHP somo la 70: jinsi ya kutuma email yenye html, picha na attachment
Katika somo hili utakwenda kujifunza jinsi ya kutuma email ambayo ina HTML, pia utajifunza kutuma email yenye picha na attachment nyinginezo kama pdf Soma Zaidi...

PHP - somo la 20 : Jinsi ya kufuta na ku update data kwenye database kwa kutumia PHP
Katika somo hili utakwenda kujifunza jinsi ya ku update na kufuta data kwenye database kwa kutumia PHP Soma Zaidi...

PHP somo la 90: Jinsi ya kutumia json data kama blog post
Katika somo hili utaweza kujifunza ni kwa nambna gani utaweza kutengeneza blog post na kuisoma kwa kutumia data za json Soma Zaidi...

PHP - somo la 15: Jinsi ya kutengeneza table kwenye database kwa kutumia PHP
Katika somo hili utakwenda kujifunza jinsi ya kutumia PHP kutengeneza tabale kwenye database ya mysql . Soma Zaidi...

PHP BLOG - somo la 6: Jinsi ya kutengeneza dashboard kwa ajili ya blog
katika post hii utajifunza jinsi ya kutengeneza ukurasa wa dashboard kwa ajili ya kutibti post Soma Zaidi...