使用Ajax請求的資料為什麼儲存不到資料庫中?後台用php寫,各位大神支個招
if(isset($_GET['content'])){
//從請求URL地址中擷取參數
$view_name=$_GET["name"];
$view_content=$_GET["content"];
$view_time=$_GET["time"];
$linkview=mysqli_connect("localhost", "root", "xxxxxxx", "wordstv") or die("資料庫連接失敗:".mysql_errno());
$queryview="insert into wordstv_user_view (user_name,user_content,time,) values ('".$view_name."','".$view_content."','".$view_time."')";
[email protected]_query($linkview, $queryview);
if($resultview){
echo $view_name."&&&".$view_content."&&&".$view_time;
}
mysqli_close($linkview);
}
?>
------解決思路----------------------
先確定ajax提交的資料是否正確擷取。
在php 最前加
$data = $_REQUEST;
file_get_contents('test.log', json_encode($data), true);
看看能否擷取到資料,如果可以,再在入庫的語句中找問題。
否則在js ajax提交的語句中找問題。
[email protected]_query($linkview, $queryview) or die(mysql_error()); 這裡也加上看看。
------解決思路----------------------
content 通常表示本文,一般比較大
如果整個傳送的資料可能超過 get 方式的 2K 限制的話,應使用 post 方式
從減少資訊泄露的角度上看,使用 POST 方式也是較為妥當的
你直接將傳入的資料入庫了,如果傳入的資料中含有特殊字元,就將導致插入失敗
你只在插入成功時輸出了資訊,卻沒在插入失敗時做出響應
無論是操作成功與失敗都應有資訊返回,這樣才方便判斷問題的所在
------解決思路----------------------
引用:
Quote: 引用:
先確定ajax提交的資料是否正確擷取。
在php 最前加
$data = $_REQUEST;
file_get_contents('test.log', json_encode($data), true);
看看能否擷取到資料,如果可以,再在入庫的語句中找問題。
否則在js ajax提交的語句中找問題。
[email protected]_query($linkview, $queryview) or die(mysql_error()); 這裡也加上看看。
謝謝啊,已經解決了
如問題解決了請結貼。