2012-04-22 47 views
0

此代码应该用编辑网页中的更改更新已在数据库中的文章,但它不起作用。它显示当前的文章,但是当我进行更改并单击“保存”没有任何更改。编辑查询不会更改数据库中的任何内容

mysql_select_db("scms", $con); 
$show_world="show_world"; 
define("IMG_URL", "http://localhost/project/show/show_home/images/"); 
define("ABS_PATH",dirname(__FILE__)); 
define("IMG_PATH",dirname(__FILE__)."/"); 
$id = $_GET['id']; 
$sql = "select * FROM $show_world where id = $id"; 
$result=mysql_query($sql); 
$row = mysql_fetch_array($result); 
if(isset($_POST['save'])) { 
    $id = $_POST['id']; 
    $topic = $_POST['topic']; 
    $author = $_POST['author']; 
    $content = $_POST['content']; 
    $picture = $_POST['picture']; 
    $date = $_POST['date']; 
    $sql = "UPDATE $show_world SET topic='".$topic."',author='".$author."', content='".$content."', date='".$date."' "; 
+1

是否有更多的SQL查询,如'WHERE id = $ id'? – gimg1 2012-04-22 10:03:59

+0

所以我应该在该查询的末尾添加'WHERE id = $ id'? – Iman25 2012-04-22 10:16:49

+0

停止使用mysql_ *函数,它们[已被弃用](http://news.php.net/php.internals/53799)。改用mysqli或PDO并绑定变量。 **不要将未经过滤的用户输入放入SQL **中。 – DCoder 2012-04-22 10:29:56

回答

0

尝试封闭变量表名是这样的:

$sql = "UPDATE {$show_world} SET topic='".$topic..... 

一件事:你的代码很容易受到SQL注入!尝试在数据库中更新之前逃避用户输入。

相关问题