使用Ajax請求的資料為何儲存不到資料庫中?後台用php寫,各位大神支個招

來源:互聯網
上載者:User
使用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()); 這裡也加上看看。

謝謝啊,已經解決了


如問題解決了請結貼。
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.