3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function updateGoals() { $response = array(); if(!empty($_POST)){ if(isset($_POST["actID"]) && isset($_POST["nutID"]) && isset($_POST["activityProgress"]) && isset($_POST["nutritionProgress"])){ $actID = intval($_POST["actID"]); $nutID = intval($_POST["nutID"]); $actProg = floatval($_POST["activityProgress"]); $nutProg = floatval($_POST["nutritionProgress"]); } $query = "UPDATE Goals SET Progress='$nutProg' WHERE GoalID=$nutID;"; $result = mysql_query($query) or die(mysql_error()); if ($result) { $response["error"] = false; $response["message"] = "Nutrtition goal updated successfully!"; } else { $response["error"] = true; $response["message"] = "Failed to update nutrtition goal!"; } $query = "UPDATE Goals SET Progress='$actProg' WHERE GoalID=$actID;"; $result = mysql_query($query) or die(mysql_error()); if ($result) { $response["error"] = false; $response["message"] = "Activity goal updated successfully!"; } else { $response["error"] = true; $response["message"] = "Failed to update activity goal!"; } if (isset($_POST["newgoalID"]) && isset($_POST["newgoal"]) && $isset($_POST["newgoalProgress"])) { $newGoalID = intval($_POST["newgoalID"]); $newgoal = $_POST["newgoal"]; $newGoalProg = floatval($_POST["newgoalProgress"]); $query = "UPDATE Goals SET Description='$newgoal',Progress='$newGoalProg' WHERE GoalID=$newGoalID;"; $result = mysql_query($query) or die(mysql_error()); } else if(isset($_POST["newgoal"]) && isset($_POST["pid"]) && isset($_POST["week"])) { $newgoal = $_POST["newgoal"]; $pid = intval($_POST["pid"]); $week = intval($_POST["week"]); $query = "INSERT INTO Goals (ParticipantID, Type, Description, WeekNumbe r) VALUES ('$pid', 'OTHER', '$newgoal', '$week');"; $result = mysql_query($query) or die(mysql_error()); } } else { $response["error"] = true; $response["message"] = "Things are missing!"; } // echo json response echo json_encode($response); } updateGoals(); ?>
Output for 5.2.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
{"error":true,"message":"Things are missing!"}
Output for 5.0.0 - 5.1.6
Fatal error: Call to undefined function json_encode() in /in/JqHsJ on line 52
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: json_encode() in /in/JqHsJ on line 52
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: json_encode() in /in/JqHsJ on line 52
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: json_encode() in /in/JqHsJ on line 52