我不明白爲什麼我的MY_SQL插入不起作用。MYSQL插入不工作
<?php
$sub = $_POST['submit'];
if($sub)
{
$title = $_COOKIE['newstitle'];
$body = $_COOKIE['newsbody'];
$sneak = $_COOKIE['newssneak'];
$date = date("Y-d-m");
$postedby = $_COOKIE['userlogin'];
$connect = mysql_connect("localhost","admin","00904684") or die("Couldn't Connect!");
mysql_select_db("dr") or die("Couldn't find DB.");
$insert = mysql_query
("
INSERT INTO news(`id`,`title`,`summary`,`body`,`date`,`postedby`)
VALUES ('NULL','".$title."','".$sneak."','".$body."','".$date."','".$postedby."')
");
mysql_close($connect);
header('Location: ../index.php');
}
else echo (mysql_error());
?>
我的代碼中工作,直到我添加了一個新的費爾德「總結」了進去,至今還沒有工作,我知道的變量正確地傳遞雖然。
這裏是我的數據庫佈局:
ID |標題|總結| body |日期| postedby
添加'if(!$ insert)echo mysql_error();'查看mySQL正在拋出什麼錯誤 – 2011-03-07 23:16:57
您有什麼錯誤?如果我編輯我的'newstitle' cookie的值爲''OR 1 = 1;'''mysql_real_escape_string()'在本例中是你的朋友,或者PDO是一個更好的朋友:) – alex 2011-03-07 23:17:49
1. * please *閱讀關於mysql_real_escape_string - 2.試着在查詢後立即回顯mysql_error(),看看你收到的錯誤並將它發佈在這裏謝謝 – Dre 2011-03-07 23:18:53