phpmyadmin Swift http删除请求与php不工作

kcwpcxri  于 2022-11-09  发布在  PHP
关注(0)|答案(1)|浏览(133)

我已经尝试了很多次在Swift,似乎问题发生在PHP文件.我不知道的数据类型$revaID正确我得到$revaID值从swift,我想使用revaID删除行从表保留,它是自动创建的.请帮助

<?php
 $host = "127.0.0.1";
 $username = "root";  
 $password = "password";
 $dbname =  "project";
// Connect to server
 $connect=mysqli_connect("127.0.0.1", "root", "password","project")
                or die ("Sorry, unable to connect database server");
  $revaID   = $_POST["revaID"]; ;
  $UserID = $_["UserID"];
   // Run the query
  $query = "DELETE FROM reservation WHERE revaID = '$revaID'";
  $result = mysqli_query($connect,$query);

   ////////////////////ignore///////// //////////////////
 if ($result) {
    print $result;
    print "Suss";
    print $revaID;
  } else {
   print "Failed to delete record!";
   print(mysqli_error($connect));}
   ////////////////// ////////////////// //////////////////
  ////////////////////ignore////////////////////////
if ($revaID){
set_include_path('/Library/WebServer/Documents/');
$id2 = array();
$id2['revaID'] = $revaID;
// Loop through each row in the result set
$json = json_encode($id2, JSON_NUMERIC_CHECK );
file_put_contents('deleterevaID.php',$json,FILE_USE_INCLUDE_PATH);}

 ////////////////// //////////////////
mysqli_close($connect);
?>

这是我老婆的代码,在编辑的时候得到了$revaID。

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == .delete{

        let UserID = userinfo[indexPath.row]
     //   print(UserID)

        userinfo.remove(at:indexPath.row)

        tableView.deleteRows(at: [indexPath], with: .fade)
        tableView.endUpdates()

       // Service.shared.deletePost(revaID:UserID.revaID) { (err) in

       // }
        let urlStr = "http://localhost/deleteres.php"
         if let url = URL(string: urlStr) {
         var urlRequest = URLRequest(url: url)
         urlRequest.httpMethod = "DELETE"
        let body = "revaID=\(UserID.revaID)"
             print("ID:",UserID.revaID)
         if let data = body.data(using: .utf8) {
         let dataTask = URLSession.shared.uploadTask(with: urlRequest,
         from: data, completionHandler: {
         data, response, error in
         if let error = error{
         print("error: \(error.localizedDescription)")
         }
            // print(UserID.revaID)
         //self.refreshBtnClicked(self)
         })
         dataTask.resume()
         }
         }

        }
        }
db2dz4w8

db2dz4w81#

swift文件中,您使用get方法发送数据,而在PHP文件中,您尝试使用post方法获取数据。
因此,与此相反:

$revaID   = $_POST["revaID"]; ;

尝试通过get方法获取数据

$revaID   = $_GET["revaID"]; ;

相关问题