3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function createNewGoals() { $response = array(); if (isset($_POST["activity"]) && isset($_POST["pid"]) && isset($_POST["activityProgress"]) && isset($_POST["nutritionProgress"]) && isset($_POST["nutrition"]) && isset($_POST["week"])) { $activity = $_POST["activity"]; $activityProg = floatval($_POST["activityProgress"]); $pid = intval($_POST["pid"]); $nutrition = $_POST["nutrition"]; $nutritionProg = floatval($_POST["nutritionProgress"]); $week = intval($_POST["week"]); $query = "INSERT INTO Goals (ParticipantID, Type, Description, WeekNumber, Progress) VALUES ('$pid', 'EXERCISE', '$activity', '$week', '$activityProg');"; $result = mysql_query($query) or die(mysql_error()); if ($result) { $response["error"] = false; $response["message"] = "Activity goal created successfully!"; } else { $response["error"] = true; $response["message"] = "Failed to create activity goal!"; } $query = "INSERT INTO Goals (ParticipantID, Type, Description, WeekNumber, Progress) VALUES ('$pid', 'NUTRITION', '$nutrition', '$week', $nutritionProg');"; $result = mysql_query($query) or die(mysql_error()); if ($result) { $response["error"] = false; $response["message"] = "Nutrtition goal created successfully!"; } else { $response["error"] = true; $response["message"] = "Failed to create nutrtition goal!"; } } else { $response["error"] = true; $response["message"] = "Things are missing!"; } // echo json response echo json_encode($response); } createNewGoals(); ?>
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/3oKkc on line 38
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: json_encode() in /in/3oKkc on line 38
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: json_encode() in /in/3oKkc on line 38
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: json_encode() in /in/3oKkc on line 38