我有一個非常惱人的問題。每當我編輯帖子,編輯第一個時,它都會丟失所有信息。我無法弄清楚,我已經爲此工作了2天。PHP編輯帖子
赫雷什形式的代碼:
<?php
$post = htmlspecialchars($_GET["id"]);
$name = $_SESSION['Username'];
if (in_array($name, $allowedposters)) {
$results = mysql_query("SELECT * FROM tool WHERE id = $post");
while($row = mysql_fetch_array($results)){
$title= $row['title'];
$details= $row['details'];
$date= $row['date'];
$author= $row['author'];
$id= $row['id'];
echo "<a href=story.php?id=";
echo $post;
echo ">Cancel edit</a> <br><br><b>";
echo $title;
echo "</b> <br><br>";
echo '
<form action="edit-new.php?story=';
echo $id;
echo '" method="post" enctype="multipart/form-data">
<textarea rows="1" cols="60" name="title" wrap="physical" maxlength="100">';
echo $title;
echo '</textarea><br>';
?>
<textarea rows="30" cols="60" name="details" wrap="physical" maxlength="10000">
<?php
echo $details;
echo '</textarea><br>';
echo '<label for="file">Upload featured image:</label><br>
<input type="file" name="file" id="file" />';
echo'<br><input type="submit" />';
}
} else {
echo "Not enough permissions.";
}
?>
。 。
下面是實際的php代碼,將信息插入數據庫:
。 。
<?php
$post = $_GET['story'];
$title = $_POST['title'];
$details = $_POST['details'];
echo 'Updated.';
$dbtype = "mysql";
$dbhost = "localhost";
$dbname = "x";
$dbuser = "xx";
$dbpass = "xxx";
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
$sql = "UPDATE tool SET title=:title, details=:details WHERE id = '$post'";
$q = $conn->prepare($sql);
$q->execute(array(
':details'=>$details,
':title'=>$title,
));
?>
同樣,我想提一提,唯一的問題是,在第一一次我編輯的職位,它就會失去它的信息。那之後它絕對不會發生在那個特定的職位上。
之後,編輯工作完美無瑕。
我已經重新寫了實際的方法,我插入信息數據庫2次 –
你有更多的1錯誤,你的整個代碼都是錯誤的。啓用'error_reporting(E_ALL);' –
@LawrenceCherone當我這樣做時我沒有收到任何錯誤 –