//check inputs for all required fields foreach ($requiredFields as $postKey) { if (!isset($inputs[$postKey]) || empty($inputs[$postKey])) { return errorHandler("missing {$postKey}", 503); } } //print debug statement if ($SERVERDEBUG) { echo "\r\n inputs:"; echo json_encode($inputs); } $prepstmt = setNames(); $prepstmt->execute(); //setup for query if (!isset($inputs['html'])) { $stmt = updateBlogAdmin($DB, $inputs['name'], $inputs['desc'], $inputs['title'], $inputs['blogid']); } else { $stmt = updateBlog($DB, $inputs['name'], $inputs['desc'], $inputs['title'], $inputs['html'], $inputs['feature'], $inputs['blogid']); } if (!$stmt) { return; } // createNewList already send error. if (!$stmt->execute()) { return errorHandler("failed to create this list {$stmt->errno}: {$stmt->error}"); } if ($stmt->affected_rows != 1) { return errorHandler("Updated {$stmt->affected_rows} rows", 503); } ?>
<?php require 'connectSql.php'; if (!isset($_POST["submit"])) { echo "Error!"; exit(0); } if (empty($_POST["caption"])) { echo '请输入标题'; exit(0); } if (empty($_POST["text"])) { echo '请输入正文'; exit(0); } $caption = $_POST['caption']; $artical = $_POST['text']; $id = $_GET['id']; $date = date("Y/m/d H:i:s", time()); $db = connect(); //$query = "UPDATE blogs SET caption = "."'".$caption."'" . ', artical = '."'".$artical."'".', // date = '."'".$date."'"." WHERE blog_id = ".$id; //$db->query($query); if (updateBlog($db, $caption, $artical, $date, $id)) { echo "Update Succeed!<br>"; } else { echo "Update Failed!<br>"; } $db->close(); ?> <a href="houtai.php" name="return">Return</a> </html>
//the verb used to run the script (e.g. GET, POST) switch ($verb) { case "GET": //just gets the entire database $results = getAllBlogs("all"); break; case "POST": //action is a variable (set by the function) sent along with any variables $action = $_REQUEST['action']; switch ($action) { case "ADD": addBlog($_REQUEST); $results = getAllBlogs("all"); break; case "UPDATE": updateBlog($_REQUEST); $results = getAllBlogs("all"); break; case "DELETE": deleteBlog($_REQUEST['code']); $results = getProductsDB("all"); break; case "search": $results = getSearchDB($_REQUEST['search']); break; default: //if the specified action isn't recognised set meta details $results["meta"]["msg"] = "action not recognised, illegal action!"; $results["meta"]["status"] = 400; $results["meta"]["ok"] = false; }