我試圖從我的數據庫更新數據,但是當我進入編輯頁面時它們不顯示。任何幫助?謝謝。我的數據庫中的數據不會顯示出來
的index.php
<?php
include_once('db.php');
if(isset($_POST['description']))
{
$description = $_POST['description'];
if(mysql_query("INSERT INTO about VALUES('','$description')"))
echo "Sucacessful Update";
else
echo "Please try again";
}
$res = mysql_query("SELECT * FROM about");
?>
<form action = "." method="POST">
Name <input type = "text" name="description"><br/>
<input type="submit" value="Save">
</form>
<?php
while($row = mysql_fetch_array($res))
echo "$row[id]. $row[description] <a href='edit.php?edit=$row[description]'>edit</a><br />";
?>
edit.php
<?php
include_once('db.php');
if(isset($_GET['edit']))
{
$id = $_GET['edit'];
$res= mysql_query("SELECT * FROM about WHERE id='$id'");
$row= mysql_fetch_array($res);
}
if(isset($_POST['newDescription']))
{
$newDescription = $_POST['newDescription'];
$id = $_POST['id'];
$sql = "UPDATE about SET description='$newDescription' WHERE id='$id'";
$res = mysql_query($sql)
or die("Could not update".mysql_error());
echo "<meta http-equiv='refresh' content='0;url=index.php'>";
}
?>
<form action="edit.php" method="POST">
Name: <input type="text" name="newDescription" value="<?php echo $row[1]; ?>"><br />
<input type="hidden" name="id" value="<?php echo $row[0]; ?>">
<input type="submit" value=" Update "/>
</form>
從我的表名是約,我有兩列這是標識和說明。我試圖在這裏做的是通過PHP編輯描述列。
**使用不推薦使用的'mysql_ *'API停止**。用準備好的語句使用'mysqli_ *'或PDO。 – Jens
嗯,首先,你的第一頁是在URL中加入'$ row ['description']',但是你正在SELECT中'id'字段中尋找這個值。 – andrewsi
謝謝先生! @andrewsi – Louie