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 4.3.0 - 7.1.0