That is my jquery code:
$(function() {
$("#edit_union").click(function() {
var tuzove = $("#tuzove").val();
var description = $("#description").val();
var union_owner = $("#union_owner").val();
var union_name = $("#union_name").val();
var uid = $("#uid").val();
var dataString = 'tuzove='+ tuzove + '&description=' + description + '&union_owner=' + union_owner + '&union_name=' + union_name + '&uid=' + uid;
$.ajax({
type: "POST",
url: "ajax/admp_ajax.php",
data: dataString,
success: function() {
$(".adm_panel_serach_user").append("<br/><span style=' color: #0099ff; font-weight: bold;'>Success.</span>");
}
});
return false;
});
});
That is ajax/admp_ajax.php page:
include_once 'classes/admin_panel.php';
$admpanel = new adminPanal();
if ($_POST['tuzove'] && $_POST['description'] && $_POST['union_owner'] && $_POST['union_owner'] && $_POST['uid'])
$admpanel->editUnion($_POST['tuzove'], $_POST['description'], $_POST['union_owner'], $_POST['union_name'], $_POST['uid']);
That is editUnion function:
public function editUnion($tyzove, $description, $ownerName, $unionName, $unionId) {
mysql_query("UPDATE `union` SET tuzove = '" . $tyzove . "', description = '" . mysql_real_escape_string($description) . "', owner_id = '" . $this->getUserId($ownerName) . "' WHERE name = '" . $unionName . "'");
if ($ownerName == $ownerName)
mysql_query("UPDATE users SET union_rank = '0', union_id = '0' WHERE username = '" . $ownerName . "'");
mysql_query("UPDATE users SET union_rank = '1', union_id = '" . $unionId . "' WHERE username = '" . $ownerName . "'");
}
Problem is that, when I click edit_union button write Success, but don’t update union :(.
Well your php page will return some content whether the sql query fails or not. This means that success will always be fired unless the page cannot be loaded for some reason. SQL failures will not cause it to fail.
Therefore you will always get your success printed but the update itself may fail. Try running the php page by itself in the browser and see any errors sql kicks up. You can also try printing the sql queries to the screen using echo statements in php and then copy these onto the sql commandline or into phpmyadmin etc.
Also a side note, since your query info is coming from a form / input fields you need to be very careful to prevent sql injection and the like. Look into using mysqli and prepared statements instead.