This is my javascript and ajax code, it's returning success but the database is not updating, any ideas? 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
$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.
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'";
Print $query and check in phpmyadmin whether the query you printed is working or not. 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.
As of php 5.5.x the original MySQL extension is now deprecated, and will generate E_DEPRECATED errors.
http://php.net/manual/en/migration55.deprecated.php
you might need to use mysqli.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.