The following function was working but now for a reason is not working... Weird thing is that the first query, returns the wrong value.However, if i put the second query in comments and have only the select query, it returns the correct value! I can't really explain this...
function change_prod_visible($id) {
$q = "SELECT prod_visible FROM tbl_products WHERE prod_id='$id'";
$r = mysql_query($q);
$row = mysql_fetch_array($r);
if ($row[0] == 1) {
$new_status = 0;
} else {
$new_status = 1;
}
mysql_free_result();
$query = "UPDATE tbl_products SET prod_visible='$new_status' WHERE prod_id='$id'";
$result = mysql_query($query);
if ($result) {
return _PROD_SUCCESSFULLY_EDITED;
} else {
return _PROD_ERROR_OCCURED . mysql_error();
}
}