2014-04-05 105 views
0

下面的代碼導致我錯誤Undefined index: id並導致整個代碼中的更大的錯誤SyntaxError: JSON.parse: unexpected character任何想法,我出錯了?這似乎是一個愚蠢的問題,但我是新來的節目,有這麼多的東西就知道了,所以這是一個有點硬在開始:)未定義的索引,syntaxerror.json.parse

protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, 
      $index = null, $content_range = null) { 
     $file = parent::handle_file_upload(
      $uploaded_file, $name, $size, $type, $error, $index, $content_range 
     ); 
     if (empty($file->error)) { 
$con = mysqli_connect("localhost","root","","login"); 
      $q1 = "SELECT MAX(id) FROM masinos"; 
      $res = mysqli_query($con,$q1); 
      $row = mysqli_fetch_array($res); 

      $max_id = $row["id"]; 
      $max_id_plus = $max_id + 1; 

      $sql = "INSERT INTO files (`carID`,`name`, `size`, `type`, `title`, `description`) 
       VALUES($max_id_plus,?, ?, ?, ?, ?)"; 
      $query = $this->db->prepare($sql); 
      $query->bind_param(
       'sisss', 
       $file->name, 
       $file->size, 
       $file->type, 
       $file->title, 
       $file->description 
      ); 
      $query->execute(); 
      $file->id = $this->db->insert_id; 
     } 
     return $file; 
    } 
+2

哪裏是JSON代碼? –

回答

1

你所要求的ID,而你沒有掛在你的選擇ID。你應該給別名ID。

改變這種

$q1 = "SELECT MAX(id) FROM masinos"; 

$q1 = "SELECT MAX(id) id FROM masinos"; 
+0

謝謝:)沒有代表給你upvote :) – Jugernaut

+0

你歡迎老兄:)! –