$sql .= $key; $ct++; } } $sql .= ") VALUES ("; $ct = 0; foreach ($updata as $key => $value) { if ($value != "" && $key != "id") { if ($ct != 0) { $sql .= ", "; } $sql .= ":" . $key; $ct++; } } $sql .= ")"; $st = $db->prepare($sql); foreach ($updata as $key => &$value) { if ($value != "") { $st->bindParam(":" . $key, $value); } } $st->execute(); $st = $db->prepare("SELECT LAST_INSERT_ID()"); $st->execute(); $lastid = $st->fetch(); $newtask = $dbh->getTask($lastid[0]); } catch (PDOException $e) { errormsg($e->getMessage()); } exitjson(array("task" => $newtask));
if (empty($updata["id"])) { errormsg("The 'taskID' is required."); } $dbh = new PDB(); $db = $dbh->db; $site = new Site($db); try { $ct = 0; $sql = "UPDATE tasks SET "; foreach ($updata as $key => $value) { if ($value != "" && $key != "id") { if ($ct != 0) { $sql .= ", "; } $sql .= $key . " = :" . $key; $ct++; } } $sql .= " WHERE id = :id"; $st = $db->prepare($sql); foreach ($updata as $key => &$value) { if ($value != "") { $st->bindParam(":" . $key, $value); } } $st->execute(); $newtask = $dbh->getTask($updata["id"]); } catch (PDOException $e) { errormsg($e->getMessage()); } exitjson(array("task" => $newtask));
<?php // check if logged in // per project or all tasks? // error_reporting(E_ALL); session_start(); session_regenerate_id(false); require_once "reqs/common.php"; require_once "reqs/pdo.php"; //require_once("reqs/auth.php"); checkLoggedIn(); $userID = $_SESSION["user"]; $taskID = param($_GET, 'taskID', ''); $dbh = new PDB(); $db = $dbh->db; $projectIDs = $dbh->getValidProjects($userID); $projectID = param($_GET, 'projectID', $projectIDs); if ($taskID !== '') { $tasks = $dbh->getTask($taskID); } else { $tasks = $dbh->getTasks($projectID); } exitjson(array("tasks" => $tasks)); /* if($st->rowCount() == 0){ errormsg("Username or password incorrect."); }; */