2016-11-21 7 views
0

Ich mache eine persönliche Website und ich wollte nur, dass es mir ein bisschen einfacher ist, meine Beiträge hinzuzufügen/zu bearbeiten, ohne manuell in phpmyadmin zu gehen.PHP & MySQL - Update Abfrage aktualisiert Datenbank nicht

Wenn ich auf die Seite edit_post.php gehe und auf update klicke, bekomme ich ein "=" - Zeichen neben der PID zB (foo.php? Pid = 3), und wenn ich es auf die Blogseite umleiten lasse aktualisiert es nicht.

Blog Seite

<?php 
 
\t session_start(); 
 
\t include_once("../IncBlog/db.php"); 
 
?> 
 
<?php include "../Includes/navHead.php"; ?> 
 
\t \t <title>Adam Brickhill - Life Journal </title> 
 
\t </head> 
 
\t <body> 
 
\t \t <div class="box"> 
 
\t \t \t <div class="header"> 
 
\t \t \t \t <nav class="nav"><p class="title"><a class="postLink" href="../IncBlog/post.php">- Lone Tree -</a></p></nav> 
 
\t \t \t </div> 
 
\t \t \t <!-- JOURNAL !--> 
 
\t \t \t <?php 
 
\t \t \t \t require_once("../nbbc/nbbc.php"); 
 

 
\t \t \t \t $bbcode = new BBCode; 
 

 
\t \t \t \t $sql = "SELECT * FROM posts ORDER BY id DESC"; 
 

 
\t \t \t \t $res = mysqli_query($db, $sql) or die(mysqli_error()); 
 

 
\t \t \t \t $posts = ""; 
 

 
\t \t \t \t if (mysqli_num_rows($res) > 0) { 
 
\t \t \t \t \t while ($row = mysqli_fetch_assoc($res)) { 
 
\t \t \t \t \t \t $id = \t \t $row['id']; 
 
\t \t \t \t \t \t $title = \t $row['title']; 
 
\t \t \t \t \t \t $img = \t \t $row['img']; 
 
\t \t \t \t \t \t $content = \t $row['content']; 
 
\t \t \t \t \t \t $date = \t $row['date']; 
 

 
\t \t \t \t \t \t $admin = "<div><a href='../IncBlog/del_post.php?pid$id'>Delete</a>&nbsp;<div><a href='../IncBlog/edit_post.php?pid$id'>Edit</a>"; 
 

 
\t \t \t \t \t \t $output = $bbcode->Parse($content); 
 

 
\t \t \t \t \t \t ob_start(); 
 
\t \t \t \t \t \t \t include('../IncBlog/blogSkel.php'); 
 
\t \t \t \t \t \t \t $posts .= ob_get_contents(); 
 
\t \t \t \t \t \t ob_end_clean(); 
 
\t \t \t \t \t } 
 
\t \t \t \t \t echo $posts; 
 
\t \t \t \t } 
 
\t \t \t \t else { 
 
\t \t \t \t \t echo "There are no posts to display"; 
 
\t \t \t \t } 
 
\t \t \t ?> 
 
\t \t \t <div class="journal"> 
 
\t \t \t \t <div class="catagories"> 
 
\t \t \t \t 
 
\t \t \t \t </div> 
 
\t \t \t \t <!-- Date !--> 
 
\t \t \t \t <!-- Picture !--> 
 
\t \t \t \t <!-- Description !--> 
 
\t \t \t </div> 
 
\t \t \t 
 

 
\t \t \t <?php include "../Includes/navFooter.php"; ?> 
 
\t \t \t <!-- SCRIPTS !--> 
 
\t \t \t <?php include "../Includes/navScriptImport.php"; ?> 
 
\t \t </div> 
 
\t </body> 
 
</html>

Seite bearbeiten

<?php 
 
\t session_start(); 
 
\t include_once("db.php"); 
 

 
\t if (!isset($_SESSION['username'])) { 
 
\t \t header("Location: login.php"); 
 
\t \t return; 
 
\t } 
 

 
\t $pid = $_SERVER['REQUEST_URI']; 
 
\t $pid = trim($pid, "/IncBlog/edit_post.php?pid"); 
 

 
\t $pid = strip_tags($pid); 
 
\t $pid = stripslashes($pid); 
 
\t $pid = mysqli_real_escape_string($db, $pid); 
 
\t //echo "$pid"; 
 

 
\t if ($pid == "") { 
 
\t \t header("Location: ../Nav/life.php"); 
 
\t } 
 

 
\t if (isset($_POST['update'])) { 
 
\t \t $title = strip_tags($_POST['title']); 
 
\t \t $content = strip_tags($_POST['content']); 
 
\t \t $img = strip_tags($_POST['image']); 
 

 
\t \t $title = mysqli_real_escape_string($db, $title); 
 
\t \t $content = mysqli_real_escape_string($db, $content); 
 
\t \t $img = mysqli_real_escape_string($db, $img); 
 

 
\t \t $date = date("l jS \of F Y h:i:s A"); 
 

 
\t \t $sql = "UPDATE posts SET title='$title', content='$content', img='$img', date='$date' WHERE id=$pid"; 
 

 
\t \t if ($title == "" || $content == "") { 
 
\t \t \t echo "The database is hungry you can't feed it nothing!"; 
 
\t \t \t return; 
 
\t \t } 
 

 
\t \t mysqli_query($db, $sql); 
 

 
\t \t header("Location: ../Nav/life.php"); 
 
\t } 
 
?> 
 
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
\t <title>Blog - Post</title> 
 
</head> 
 
<body> 
 
\t \t <?php 
 
\t \t \t $sql_get = "SELECT * FROM posts WHERE id=$pid LIMIT 1"; 
 
\t \t \t $res = mysqli_query($db, $sql_get); 
 

 
\t \t \t if (mysqli_num_rows($res) > 0) { 
 
\t \t \t \t while ($row = mysqli_fetch_assoc($res)) { 
 
\t \t \t \t \t $title = $row['title']; 
 
\t \t \t \t \t $content = $row['content']; 
 
\t \t \t \t \t $img = $row['image']; 
 

 
\t \t \t \t \t echo "<form action='edit_post.php?pid=$pid' method='post' enctype='multipart/form-data'>"; 
 
\t \t \t \t \t echo " \t <input placeholder='Title' type='text' name='title' value='$title' autofocus size='48'><br /><br />"; 
 
\t \t \t \t \t echo " \t <input placeholder='Image' type='text' name='image' value='$img' autofocus size='48'><br /><br />"; 
 
\t \t \t \t \t echo " \t <textarea placeholder='Content' name='content' rows='40' cols='40'>$content</textarea><br />"; 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t ?> 
 

 
\t \t <input type="submit" name="update" value="Update"> 
 
\t </form> 
 
</body> 
 
</html>

+0

Sie müssen auf Fehler über PHP und die Abfragen prüfen, Sie tun das nicht. und var_dump die ID und andere Variablen –

+0

Ich habe bereits, Die ID ist 1 und die PID ist 1 Klick Update und nichts passiert. –

+0

Ich entfernte BEHOBEN vom Titel in einer Bearbeitung. Wenn eine Antwort unten gelöst wurde, dann akzeptiere eins. Wenn dies nicht der Fall ist, können Sie Ihre eigene Antwort posten. Die Annahme einer Antwort teilt dem System automatisch mit, dass die Frage gelöst wurde. Ihrerseits sind keine weiteren Maßnahmen erforderlich. –

Antwort

0

Sie müssen die Spalten festlegen und die Werte für die Spalten festlegen.

UPDATE posts SET (title, content, img, date) VALUES ($title, $content, $img, $date) WHERE id = $pid; 
+0

Das hat leider auch nicht funktioniert –

0
$date = date("l jS \of F Y h:i:s A"); 

Verwendung anstelle von oben Linie

$date = date('Y-m-d H:i:s', strtotime()); 

$sql = 'UPDATE posts SET title='".$title."', content='".$content."', img='".$img."', date='".$date."' WHERE id='".$pid."'"; 
+0

Nö funktioniert auch nicht, beide Termine funktionieren. Das ist nicht mein Problem, das Problem ist, wenn ich auf Update klicke, um einen Beitrag zu aktualisieren, werden die Änderungen nicht übernommen. –

0

Ok, so habe ich es heraus, sehr kleine Programmierer Blindheit aber hey wir alle es.

Linie 66 echo "<form action='edit_post.php?pid$pid' method='post' enctype='multipart/form-data'>";
Wo es heißt "? Pid $ pid" Ich musste nur das "=" entfernen, das ich dort hatte.

Verwandte Themen