我有我的代碼試圖編輯文章 小(42小時)的問題 - 只是基本的editNews.php基本edit.php不需額外更新數據
當我選擇文章編輯出現的數據從DB和形式時 我點擊「更新」,它沒有返回錯誤,但數據wasn't更新
<?PHP
connection to database blah blah
?>
<?php
if(isset($_POST['update']))
{
$newsid = $_POST['newsid'];
$date=$_POST['date'];
$time=$_POST['time'];
$location=$_POST['location'];
$result=mysql_query("UPDATE news SET date='$date',time='$time',location='$location', WHERE newsid=$newsid");
header("Location: listNews.php");
}
}
?>
<?php
$newsid = $_GET['newsid'];
$result=mysql_query("select * from news where newsid=$newsid");
while($res=mysql_fetch_array($result))
{
$date = $res['date'];
$time = $res['time'];
$location = $res['location'];
}
?>
這是形式 - 只是正常的一個....
<form method="post" action="editNews.php" name="form1">
每個項目是像
<input type="text" name="headline" value="<?php echo $location;?>" id="UserName">
和
<input type="hidden" name="newsid" value=<?php echo $_GET['newsid'];?>
<input name="update" type="submit" value="update" />
最有可能出現的是,我不看,但「看到」的東西已經採取現在幾乎2天 ......有沒有一種可能我在mySql中沒有「編輯」權限?
我不認爲你的更新查詢最後一個逗號應該在那裏。 –
請注意,您已經編寫了一個易受[SQL注入](http://en.wikipedia.org/wiki/SQL_injection)漏洞影響的腳本,因爲您尚未清理SQL查詢中的任何用戶提供的變量。請使用[PHP Prepared Statements](http://php.net/manual/en/pdo.prepared-statements.php)來防止這些漏洞。謝謝。 – sarnold