2016-04-06 24 views
1

Bir resim yüklemesini php üzerinden mysql,
satırına GÜNCELLEŞTIRMEK için kullanıcı kimliğini kullanmaya çalışıyorum. mysql GÜNCELLEME sorgusu php aracılığıyla görüntü yüklemesi için çalışmaz

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(image_type,image, image_size, image_name) VALUES ('images/1459926006.png','png'' at line 1

Sadece dizimi hatası nedir göremiyorum:
Ancak bu hatayı veren tutar.

PHP:

function upload(){ 
/*** check if a file was uploaded ***/ 
if(is_uploaded_file($_FILES['userfile']['tmp_name']) && getimagesize($_FILES['userfile']['tmp_name']) != false) 
    { 
    /*** get the image info. ***/ 
    $size = getimagesize($_FILES['userfile']['tmp_name']); 
    /*** assign our variables ***/ 
    $type = $size['mime']; 
    $imgfp = fopen($_FILES['userfile']['tmp_name'], 'rb'); 
    $size = $size[3]; 
    $name = $_FILES['userfile']['name']; 
    $maxsize = 99999999; 


    /*** check the file is less than the maximum file size ***/ 
    if($_FILES['userfile']['size'] < $maxsize) 
     { 
     /*** connect to db ***/ 
     $dbh = new PDO("mysql:host=localhost;dbname=table", 'username', 'password'); 

       /*** set the error mode ***/ 
       $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 

      /*** our sql query ***/ 
     $stmt = $dbh->prepare("UPDATE users (image_type,image, image_size, image_name) VALUES (?,?,?,?) WHERE user_id=?"); 

     /*** bind the params ***/ 
     $stmt->bindParam(1, $type); 
     $stmt->bindParam(2, $imgfp, PDO::PARAM_LOB); 
     $stmt->bindParam(3, $size); 
     $stmt->bindParam(4, $name); 
     $stmt->bindParam(4, $name); 
     $stmt->bindParam(5, $_SESSION['user_id']); 

     /*** execute the query ***/ 
     $stmt->execute(); 
     } 
    else 
     { 
     /*** throw an exception is image is not of type ***/ 
     throw new Exception("File Size Error"); 
     } 
    } 
else 
    { 
    // if the file is not less than the maximum allowed, print an error 
    throw new Exception("Unsupported Image Format!"); 
    } 
} 
?> 

cevap

2

hem

Değişim

$stmt = $dbh->prepare("UPDATE users (image_type,image, image_size, image_name) VALUES (?,?,?,?) WHERE user_id=?"); 

için

$stmt = $dbh->prepare("UPDATE users SET image_type=?, image=?, image_size=1 ,image_name=? WHERE user_id=?"); 

farklıdır Ve ar update query sözdizimi insert query olarak kullanmayın e $stmt->bindParam(4, $name); iki kez

$stmt->bindParam(1, $type); 
     $stmt->bindParam(2, $imgfp, PDO::PARAM_LOB); 
     $stmt->bindParam(3, $size); 
     $stmt->bindParam(4, $name); 
     // $stmt->bindParam(4, $name);// comment it 
     $stmt->bindParam(5, $_SESSION['user_id']); 

Kontrol bağlayıcı Update query syntax

+0

Artık bir hata yok, ancak hala güncelleme yok. Kullanıcı kimliğini yanlış anlamalıyım. – Kez

+0

Evet, oturum kimliğinizi kontrol edin! sayfanızın en üstünde oturuma başladığınızdan emin olun !! – Saty

+0

lol :) Yaptığımdan emin oldum. ama sanırım yanlış yönlendiriyorum. – Kez

1

Güncellemeniz SQL sorgusu sözdizimi yanlıştır. aşağıdaki gibi Sorgunuzla değiştirin:

Gönderen:

$stmt = $dbh->prepare("UPDATE users (image_type,image, image_size, image_name) VALUES (?,?,?,?) WHERE user_id=?"); 

Değiştir:

UPDATE `users` 
    SET `image_type` = ?, 
     `image` = ?, 
     `image_size` = ?, 
     `image_name` = ? 
WHERE `user_id` = ? 

Şimdi deneyin !!!!!

+0

Çözümünüz de doğrudur! – Saty