想知道如何驗證此提交表單的輸入。通過驗證我的意思是保持SQL注入安全。任何幫助將非常感激。謝謝。
<?php
session_start();
if(!session_is_registered(ausername)){
header("location:main_login.php");
}
include ("header.php");
include ("../db.php");
$catname = $_POST['catname'];
$catdisc = $_POST['catdisc'];
$id = $_GET['id'];
if (isset($id))
{
$query = "SELECT * FROM categories WHERE catid='$id'";
$result= mysql_query($query) or die ('Mysql Error');
}
//Get category name and discription
while($row = mysql_fetch_array($result)){
$cname = $row['catname'];
$cdisc = $row['catdisc'];
}
?>
<?php
$result= mysql_query ("UPDATE categories SET catname='$catname', catdisc='$catdisc' WHERE catid='$id'")
or die ('Error Updating');
?>
<h1>Edit Categories</h1>
<form method="post" action="../admin/edit_cat.php?id=<?php echo $id;?>">
Category Name: <input type="text" name="catname" value="<?php echo $cname;?>"><br/>
Category Discription: <TEXTAREA NAME="catdisc"ROWS="3" COLS="25"><?php echo $cdisc;?></TEXTAREA><br/><br/>
<input type="submit" value="Update Category"/>
</form>
<?php
include ("footer.php");
?>
我以前修復並回答了這段代碼:http://stackoverflow.com/questions/6705191/editing-mysql-recode-using-a-html-form/6705379#6705379 -1 –