I'm not sure what's happening. I'm trying to update a 'users' table with a value of 0 using a function that suspends a user. The column name is 'active', tinyint(1) with a default value of 0, and I've tried the query with 'active = 0', 'active = false', active = !active', 'active = NOT active', active = 'DEFAULT', none of these queries are returning an error, but none of them are updating the table... I've also tried binding the value in numerous ways to no avail...
function suspendUser($id){
global $dbc;
$sus = $dbc->prepare("UPDATE users SET active = 0 WHERE user_id = :id");
$sus->bindParam(':id', $id, PDO::PARAM_INT);
$sus->execute();
if($sus->rowCount() > 0){
return true;
}
else{
return 'There was an error with your request.';
}
}
this is in my config file
try {
$dbc = new PDO("mysql:host=$db_host;dbname=$db_name;charset=utf8", $db_username, $db_password);
$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }
catch(PDOException $e){
echo "Connection failed: " . $e->getMessage(); }
// create the error handler
function my_error_handler($e_number, $e_message, $e_file, $e_line, $e_vars){
global $debug, $contact_email;
$message = "An error occurred in script '$e_file' on line $e_line: $e_message";
$message .= print_r($e_vars, 1);
if($debug){
echo '<div class="error">'.$message.'</div>';
debug_print_backtrace();
}
else{
error_log($message, 1, $contact_email);
if(($e_number != 'E_NOTICE') && ($e_number < 2048)){
echo '<div class="error">A system error occurred. We apologize for the inconvenience.</div>';
}
}
}
set_error_handler('my_error_handler');
this is the javascript function
function suspendUser(uid){
$.ajax({ url: 'lib/user-edit.php',
data:{action: 'suspend', id: uid},
type:'post',
success: function(t){
$('#' + uid).prepend('<p>'+t+'<br>Sucessfully suspended</p>');
}
});
}
and then
if(isset($_POST['action'])){
$action = $_POST['action'];
}
if(isset($_POST['id'])){
$id = $_POST['id'];
}
if(isset($_POST['role'])){
$role = $_POST['role'];
}
else{
return 'There was an error with your request.';
}
// define the function to execute based on the posted action
if($action == 'change'){
changeRole($id);
}
if($action == 'delete'){
deleteUser($id);
}
if($action == 'suspend'){
suspendUser($id);
}
I've added this to the function:
function suspendUser($id){
global $dbc;
$sus = $dbc->prepare("UPDATE users SET active = 0 WHERE user_id = :id");
$sus->bindParam(':id', $id, PDO::PARAM_INT);
$sus->execute();
if (!$dbc->execute()) {
$err = print_r($dbc->errorInfo());
return $err;
}
if($sus->rowCount() > 0){
$err = print_r($dbc->errorInfo());
return $err;
}
else{
$err = print_r($dbc->errorInfo());
return $err;
}
}
I'm still not getting errors.