简体   繁体   English

Ajax返回成功但不更新数据库

[英]Ajax returning success but not updating database

This is my javascript and ajax code, it's returning success but the database is not updating, any ideas? 这是我的javascript和ajax代码,返回成功,但数据库未更新,有什么想法吗? Thanks. 谢谢。 SOLVED 解决了

        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);
        }});

        }

This is my code on updateproductsgo.php 这是我在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());

Updated the $query, didn't make a difference though. 更新了$ query,虽然没有任何变化。

Solved! 解决了! There was an = missing off the url. 网址中缺少=。 Basic stuff!! 基本的东西!

您的更新查询缺少逗号

$query = "UPDATE products SET name = '$name', keywords = '$keywords', description = '$description', cat1 = '$cat1', cat2 = '$cat2', cat3 = '$cat3' WHERE id = $id";

You are missing comma and single quote in the 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'“;

Print $query and check in phpmyadmin whether the query you printed is working or not. 打印$ query并在phpmyadmin中检查您打印的查询是否有效。 if not then check your query you missed comma at each place where you are setting a new value. 如果不是,请检查您的查询,您在设置新值的每个位置都缺少逗号。

Find out what version of php you are using. 找出您正在使用的PHP版本。

As of php 5.5.x the original MySQL extension is now deprecated, and will generate E_DEPRECATED errors. 从PHP 5.5.x开始,原来的MySQL扩展名已被弃用,并将生成E_DEPRECATED错误。

http://php.net/manual/en/migration55.deprecated.php http://php.net/manual/en/migration55.deprecated.php

you might need to use mysqli. 您可能需要使用mysqli。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM