[英]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.