[英]Ajax returning success but not updating database
這是我的javascript和ajax代碼,返回成功,但數據庫未更新,有什么想法嗎? 謝謝。 解決了
function send_data()
{
var name = $('#name').val();
var keywords = $('#keywords').val();
var description = $('#description').val();
var cat1 = $('#cat1').val();
var cat2 = $('#cat2').val();
var cat3 = $('#cat3').val();
var id = $('#id').val();
$.ajax({
url: "updateproductsgo.php?name=" + name + "&keywords=" + keywords + "&description=" + description + "&cat1=" + cat1 + "&cat2=" + cat2 + "&cat3" + cat3 + "&id=" + id,
type: 'GET',
success: function(result) {
alert('success');
// use the result as you wish in your html here
jQuery("#results").html(result);
}});
}
這是我在updateproductsgo.php上的代碼
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("xxx",$con);
$id=$_GET['id'];
$name=$_GET['name'];
$keywords=$_GET['keywords'];
$description=$_GET['description'];
$cat1=$_GET['cat1'];
$cat2=$_GET['cat2'];
$cat3=$_GET['cat3'];
$query = "UPDATE xxx SET name = '$name', keywords = '$keywords', description = '$description', cat1 = '$cat1', cat2 = '$cat2', cat3 = '$cat3' WHERE id = '$id'";
echo $query;
mysql_query($query) or die(mysql_error());
更新了$ query,雖然沒有任何變化。
解決了! 網址中缺少=。 基本的東西!
您的更新查詢缺少逗號
$query = "UPDATE products SET name = '$name', keywords = '$keywords', description = '$description', cat1 = '$cat1', cat2 = '$cat2', cat3 = '$cat3' WHERE id = $id";
您在查詢中缺少逗號和單引號。
$ query =“更新產品SET名稱='$ name',關鍵字='$ keywords',說明='$ description',cat1 ='$ cat1',cat2 ='$ cat2',cat3 ='$ cat3',其中id ='$ id'“;
打印$ query並在phpmyadmin中檢查您打印的查詢是否有效。 如果不是,請檢查您的查詢,您在設置新值的每個位置都缺少逗號。
找出您正在使用的PHP版本。
從PHP 5.5.x開始,原來的MySQL擴展名已被棄用,並將生成E_DEPRECATED錯誤。
http://php.net/manual/en/migration55.deprecated.php
您可能需要使用mysqli。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.