Two things:
You don't have
$mysql_conn
available to your function. You can pass it as a parameter or use theglobal
keyword to make it available in your function.When there is a MySQL error you don't actually return a response. You return nothing.
As I mentioned in my comments, this code is insecure and vulnerable. Please fix that, too.
.
function creditBal($user_id, $amt, $mysql_conn)
{
$mysql_query = "UPDATE Accounts SET BALANCE=BALANCE+$amt WHERE ID=$user_id";
$result = mysql_query($mysql_query, $mysql_conn);
if (!$result)
{
# die('MySQL Error: ' . mysql_error());
$json_array = array(
'response' => 'mysql_error'
);
}
else {
$json_array = array(
'response' => 'success',
);
}
mysql_close($mysql_conn);
return json_encode($json_array);
}
if ($action == 'creditBal')
{
$user_id = $_GET['user_id'];
$amt = $_GET['amt'];
echo creditBal($user_id, $amt, $mysql_conn);
}