Updating a database with jQuery using AJAX

I'm having trouble getting this AJAX code to update my database. The code is a image that \[code\]onClick\[/code\] will run the command to update the databaseHTML:\[code\]<a> <img class = "heart" src = "http://stackoverflow.com/questions/15737700/images/heart.png" onClick = "favUpdate(0,1)" onMouseover = "this.src='http://stackoverflow.com/questions/15737700/images/heart_mo.png'" onMouseout = "this.src='http://stackoverflow.com/questions/15737700/images/heart.png'"/></a>\[/code\]Javascript code:\[code\]function favUpdate(fav_up, id_up) { $.ajax({ type: 'post', url: 'includes/fav_update.php', data: {favorite: fav_up, id: id_up}, success: function(output) { alert('success, server says ' + output + 'Variables passed are '+fav_up+' '+id_up); }, error: function() { alert('something went wrong, Favorite update failed'); } });}\[/code\]PHP code:\[code\]<?php require_once('../Connections/main.php'); $fav_update = mysql_real_escape_string($_POST['favorite']); $fav_id = mysql_real_escape_string($_POST['id']); $query = "UPDATE projects SET favorite = $fav_update WHERE id = $fav_id"; mysql_query($query, $main); ?>\[/code\]main.php\[code\]<?php$hostname_main = "localhost";$database_main = "test";$username_main = "root";$password_main = "";$main = mysql_pconnect($hostname_main, $username_main, $password_main) or trigger_error(mysql_error(),E_USER_ERROR); ?>\[/code\]Does anyone know why it's not updating the database and why the "option" isn't getting data for the variable?
 
Back
Top