function signup()
{
    try {
        $dbh = dbConnect::getInstance()->dbh;
    } catch (PDOException $e) {
        print "Error!: " . $e->getMessage() . "<br/>";
        die;
    }
    $sql = "insert into member ";
    $sql .= "(email, member_name, address, password, province_id, province_name, amphur_id, amphur_name, district_id, district_name, postcode) ";
    $sql .= "values";
    $sql .= "(:email, :member_name, :address, :password, :province_id, :province_name, :amphur_id, :amphur_name, :district_id, :district_name, :postcode)";
    $stmt = $dbh->prepare($sql);
    $stmt->bindValue(":email", $_POST["txtEmail"]);
    $stmt->bindValue(":member_name", empty($_POST["txtName"]) ? null : $_POST["txtName"]);
    $stmt->bindValue(":address", empty($_POST["txtAddress"]) ? null : $_POST["txtAddress"]);
    $stmt->bindValue(":password", $_POST["txtPassword"]);
    $stmt->bindValue(":province_id", doExplode($_POST["cboProvince"])[0]);
    $stmt->bindValue(":province_name", doExplode($_POST["cboProvince"])[1]);
    $stmt->bindValue(":amphur_id", empty($_POST['cboAmphur']) ? null : doExplode($_POST["cboAmphur"])[0]);
    $stmt->bindValue(":amphur_name", empty($_POST['cboAmphur']) ? null : doExplode($_POST["cboAmphur"])[1]);
    $stmt->bindValue(":district_id", empty($_POST['cboDistric']) ? null : doExplode($_POST["cboDistric"])[0]);
    $stmt->bindValue(":district_name", empty($_POST['cboDistric']) ? null : doExplode($_POST["cboDistric"])[1]);
    $stmt->bindValue(":postcode", $_POST["txtPostCode"]);
    if ($stmt->execute()) {
        header("Content-Type: application/json");
        echo json_encode(array("result" => "success"));
    } else {
        header("Content-Type: application/json");
        echo json_encode($stmt->errorInfo());
    }
}
function doWork()
{
    try {
        $dbh = dbConnect::getInstance()->dbh;
    } catch (PDOException $e) {
        print "Error!: " . $e->getMessage() . "<br/>";
        die;
    }
    $sql = "update member set member_name = :member_name, address = :address, password = :password ";
    $sql .= ",province_id = :province_id, province_name = :province_name ";
    $sql .= ",amphur_id = :amphur_id, amphur_name = :amphur_name, ";
    $sql .= ",district_id = :district_id, district_name = :district_name ";
    $sql .= ",postcode = :postcode ";
    $sql .= "where email = :email";
    $stmt = $dbh->prepare($sql);
    $stmt->bindValue(":member_name", $_POST["txtName"]);
    $stmt->bindValue(":address", $_POST["txtAddress"]);
    $stmt->bindValue(":password", $_POST["txtPassword"]);
    $stmt->bindValue(":province_id", doExplode($_POST["cboProvince"])[0]);
    $stmt->bindValue(":province_name", doExplode($_POST["cboProvince"])[1]);
    $stmt->bindValue(":amphur_id", doExplode($_POST["cboAmphur"])[0]);
    $stmt->bindValue(":amphur_name", doExplode($_POST["cboAmphur"])[1]);
    $stmt->bindValue(":district_id", doExplode($_POST["cboDistrict"])[0]);
    $stmt->bindValue(":district_name", doExplode($_POST["cboDistrict"])[1]);
    $stmt->bindValue(":postcode", $_POST["txtPostCode"]);
    $stmt->bindValue(":email", $_POST["email"]);
    if ($stmt->execute()) {
        header("Content-Type: application/json");
        echo json_encode(array("result" => "success"));
    } else {
        header("Content-Type: application/json");
        echo json_encode($stmt->errorInfo());
    }
}
示例#3
0
 function updateMember()
 {
     if ($this->get_request_method() != "POST") {
         $this->response('', 406);
     }
     //begin upload file
     $data = $this->_request["fileToUpload"];
     $target_dir = "uploads/";
     $oldUpload = $this->_request["oldUpload"];
     if (!empty($data) && $data != 'undefined') {
         $this::deleteOldFile($target_dir);
         list($type, $data) = explode(';', $data);
         list(, $data) = explode(',', $data);
         $data = str_replace(' ', '+', $data);
         $data = base64_decode($data);
         $mimetype = $this::getImageMimeType($data);
         //$target_file = $target_dir . basename($_FILES[$this->_request["fileToUpload"]]["name"]);
         $photo = $target_dir . $this->_request['email'] . '.' . $mimetype;
         file_put_contents('../' . $photo, $data);
     } else {
         if (!empty($oldUpload)) {
             $photo = $oldUpload;
         } else {
             $photo = null;
             $this::deleteOldFile($target_dir);
         }
     }
     // $uploadOk = 1;
     // $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
     // // Check if image file is a actual image or fake image
     //    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
     //    if($check !== false) {
     //        //$this->response("File is an image - " . $check["mime"] . ".", 222);
     //        $uploadOk = 1;
     //    } else {
     //        $this->response("File is not an image.", 500);
     //        $uploadOk = 0;
     //    }
     // // Check if file already exists
     // if (file_exists($target_file)) {
     //     $this->response("Sorry, file already exists.", 500);
     //     $uploadOk = 0;
     // }
     // // Check file size
     // if ($_FILES["fileToUpload"]["size"] > 500000) {
     //     $this->response("Sorry, your file is too large.", 500);
     //     $uploadOk = 0;
     // }
     // // Allow certain file formats
     // if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
     // && $imageFileType != "gif" ) {
     //     $this->response("Sorry, only JPG, JPEG, PNG & GIF files are allowed.", 500);
     //     $uploadOk = 0;
     // }
     // // Check if $uploadOk is set to 0 by an error
     // if ($uploadOk == 0) {
     //     $this->response("Sorry, your file was not uploaded.", 500);
     // // if everything is ok, try to upload file
     // } else {
     //     if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
     //         $this->response("The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.", 200);
     //     } else {
     //         $this->response("Sorry, there was an error uploading your file.", 500);
     //     }
     // }//upload file
     try {
         $dbh = dbConnect::getInstance()->dbh;
     } catch (PDOException $e) {
         $this->response("Error!: " . $e->getMessage() . "<br/>", 500);
         die;
     }
     $sql = "update member set member_name = :member_name, address = :address, password = :password ";
     $sql .= ",province_id = :province_id, province_name = :province_name ";
     $sql .= ",amphur_id = :amphur_id, amphur_name = :amphur_name ";
     $sql .= ",district_id = :district_id, district_name = :district_name ";
     $sql .= ",postcode = :postcode, height_1 = :height_1, height_2 = :height_2 ";
     $sql .= ",photo = :photo ";
     $sql .= "where email = :email";
     $stmt = $dbh->prepare($sql);
     $stmt->bindValue(":member_name", $this->_request["txtName"]);
     $stmt->bindValue(":address", $this->_request["txtAddress"]);
     $stmt->bindValue(":password", $this->_request["txtPassword"]);
     $stmt->bindValue(":province_id", doExplode($this->_request["cboProvince"])[0]);
     $stmt->bindValue(":province_name", doExplode($this->_request["cboProvince"])[1]);
     $stmt->bindValue(":amphur_id", empty($_POST['cboAmphur']) ? null : doExplode($this->_request["cboAmphur"])[0]);
     $stmt->bindValue(":amphur_name", empty($_POST['cboAmphur']) ? null : doExplode($this->_request["cboAmphur"])[1]);
     $stmt->bindValue(":district_id", empty($_POST['cboDistrict']) ? null : doExplode($this->_request["cboDistrict"])[0]);
     $stmt->bindValue(":district_name", empty($_POST['cboDistrict']) ? null : doExplode($this->_request["cboDistrict"])[1]);
     $stmt->bindValue(":postcode", $this->_request["txtPostCode"]);
     $stmt->bindValue(":photo", $photo);
     $stmt->bindValue(":height_1", $this->_request["txtHeight_1"]);
     $stmt->bindValue(":height_2", $this->_request["txtHeight_2"]);
     $stmt->bindValue(":email", $this->_request["email"]);
     if ($stmt->execute()) {
         $this->response(json_encode(array("result" => "success")), 200);
     } else {
         $this->response(json_encode($stmt->errorInfo()), 500);
     }
 }