Reputation: 13
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!!
Upvotes: 0
Views: 946
Reputation: 356
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.
Upvotes: 0
Reputation: 68
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.
Upvotes: 0
Reputation: 29
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'";
Upvotes: 0
Reputation: 9476
your update query have missing comma
$query = "UPDATE products SET name = '$name', keywords = '$keywords', description = '$description', cat1 = '$cat1', cat2 = '$cat2', cat3 = '$cat3' WHERE id = $id";
Upvotes: 1