2017-08-09 85 views
2

你好我想通过我的形式和邮递员提交更新请求,但我不断收到同样的事情在响应,它的工作错误更新记录

updated

没有什么是我的数据库在不断变化所有。

我在这里的功能

function update(Request $request, Response $response) { 
    $id = $request->getAttribute('id'); 
    $name = $request->getParam('name'); 
    $start = $request->getParam('start'); 
    $end = $request->getParam('end'); 


    $sql = "UPDATE table_timing SET 
       name = :name, 
       start = :start, 
       end = :end 

      WHERE table_timing.id = :id"; 

    try { 
     $db = new db(); 
     $db = $db->connect(); 
     $stmt = $db->prepare($sql); 

     $stmt->bindParam(":id", $id); 
     $stmt->bindParam(':name', $name); 
     $stmt->bindParam(':start', $start); 
     $stmt->bindParam(':end', $end); 


     $stmt->execute(); 

     $db = null; 

     $response->getBody()->write 
      (' 
      { 
       "notice": 
       { 
        "status":"200", 
        "message":"Updated" 
       } 
      }'); 

    } catch(PDOException $e) { 
     $response->getBody()->write 
     (' 
     { 
      "error": 
      { 
       "message":'. $e->getMessage() .' 
      } 
     }'); 
    } 
}; 

这里就是邮递员就是邮递员在SQL返回

{ "error": { "message":SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null } }

直接其做工精细

查询进出口运行直接在sql上是

UPDATE `table_timing` SET `name`='2016',`start`='2017-06-18 21:29:06',`end`='2017-06-18 21:29:06' WHERE `id`='1' 

的功能是通过以下途径调用我的API

这里是如何执行机构将它们

if (isset($_GET['id'])) { 
    $id = (int) $_GET['id']; 
    if (isset($_POST['submit'])) { 

     $sName = ''; 
     $sStart = ''; 
     $sEnd = ''; 


     if(isset($_POST['sname'])){ 
      $sName = $_POST['sname']; 
     }      
     if(isset($_POST['sstart'])){ 
      $sName = $_POST['sstart']; 
     } 
     if(isset($_POST['send'])){ 
      $sName = $_POST['send']; 
     } 

      //SQL queries 
      $raw = [ 
        'name' => $sName, 
        'start' => $sStart, 
        'end' => $sEnd 
      ]; 
      $data = http_build_query ($raw); 

      $result = file_get_contents(
      BASE_URL . '/timing/update/'.$id, 
      false,         
      stream_context_create(array(
       PROTOCOL => array(
        'method' => 'PUT', 
        'header' => array(
         'Authorization: Bearer '.$token, 
         'Content-Length: ' . strlen($data), 
         'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' 
        ),         
        'content' => $data 
       ) 
      )) 
     ); 

     $response = json_decode($result, false); 
     echo $response->notice->message; 
    } 
} 

我试图打印$原始$数据的$ id $ apikey都正确显示

+0

使用报价开始和结束日期'start' = '2017年6月18日21:29:06','end' ='2017- 06-18 21:29:06' –

+0

@RavinderReddy在我的PHP呢? – mirvatJ

+0

您可以打印$请求并查看名称的值是否不为空? –

回答

0

我想通了,

我有要求PARAMS

$id = $request->getAttribute('id'); 
$name = $request->getParam('name'); 
$start = $request->getParam('start'); 
$end = $request->getParam('end'); 

不同于的那些被发送

$raw = [ 
     'name' => $sName, 
     'start' => $sStart, 
     'end' => $sEnd 
     ];