2016-04-08 33 views
1

Aynı sorunla başka bir besleme varsa özür dilerim, önerilen çözümler denedim ama yine de hata alıyorum ve neden göremiyorum!sql güncelleştirmesi yürütülüyor

Tablodaki bir satırı bir html formu kullanarak güncelleştirmek istiyorum. Ben mevcut değerlerle formu doldurulur ve bu düzenlemek ve form gönderildiğinde bunları güncellemek için muktedir istiyorum ama bu hatayı alıyorum var: Burada

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in /Applications/XAMPP/xamppfiles/htdocs/love-deals/admin/update_offer.php:46 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/love-deals/admin/update_offer.php(46): PDOStatement->execute(Array) #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/love-deals/admin/update_offer.php on line 46

php/sql kodudur:

if(isset($_POST['update'])) { 
$updateTitle = trim($_POST['title']); 
$updateDesc = trim($_POST['desc']); 
$updateRedeem = trim($_POST['redeem']); 
$updateStart = trim($_POST['start']); 
$updateExpiry = trim($_POST['expiry']); 
$updateCode = trim($_POST['code']); 
$updateTerms = trim($_POST['terms']); 
$updateImage = trim($_POST['image']); 
$updateUrl = trim($_POST['url']); 

$updateSql = 'UPDATE codes SET (title,description,redemption,start,expiry,textcode,terms,image,url) = (:title,:description,:redeem,:start,:exp,:code,:terms,:image,:url) WHERE id=:offerid'; 
$update = $db->prepare($updateSql); 
$update->execute(array(':title'=>$updateTitle,':description'=>$updateDesc,':redeem'=>$updateRedeem,':start'=>$updateStart,':exp'=>$updateExpiry,':code'=>$updateCode,':terms'=>$updateTerms,':image'=>$updateImage,':url'=>$updateUrl,':id'=>$offerID)); 
} 

ve html formu: ben yanlış yapıyorum

<form id="update_offer" class="col-md-6 col-md-offset-3" method="post" action="update_offer.php?id=<?php echo $offerID; ?>"> 
     <div class="form-group col-md-12"> 
      <label class="col-md-12" for="title">Title</label> 
      <input id="title" class="form-control col-md-12" type="text" name="title" placeholder="Offer Title" value="<?php echo $title; ?>" required> 
     </div> 
     <div class="form-group col-md-12"> 
      <label class="col-md-12" for="desc">Description</label> 
      <textarea id="desc" class="form-control col-md-12" name="desc" placeholder="Description" value="<?php echo $desc; ?>"></textarea> 
     </div> 
     <div class="form-group col-md-12"> 
      <label class="col-md-12" for="redeem">Redemption</label> 
      <input id="redeem" class="form-control col-md-12" type="text" name="redeem" placeholder="Where to redeem" value="<?php echo $redeem; ?>" required> 
     </div> 
     <div class="form-group col-md-12"> 
      <label class="col-md-12" for="start">Start Date</label> 
      <input id="start" class="form-control col-md-12" type="date" name="start" value="<?php echo $startDate->format('Y-m-d'); ?>" min="<?php echo date('Y-m-d') ?>" max="2021-12-31" required> 
     </div> 
     <div class="form-group col-md-12"> 
      <label class="col-md-12" for="expiry">Expiry Date</label> 
      <input id="expiry" class="form-control col-md-12" type="date" name="expiry" value="<?php echo $expDate->format('Y-m-d'); ?>" min="<?php echo date('Y-m-d') ?>" max="2021-12-31" required> 
     </div> 
     <div class="form-group col-md-12"> 
      <label class="col-md-12" for="code">Code</label> 
      <input id="code" class="form-control col-md-12" type="text" name="code" placeholder="Code (if applicable)" value="<?php echo $code; ?>"> 
     </div> 
     <div class="form-group col-md-12"> 
      <label class="col-md-12" for="terms">Terms</label> 
      <textarea id="terms" class="form-control col-md-12" name="terms" placeholder="Terms & Conditions" value="<?php echo $terms; ?>" required></textarea> 
     </div> 
     <div class="form-group col-md-12"> 
      <label class="col-md-12" for="url">Offer URL</label> 
      <input id="url" class="form-control col-md-12" type="text" name="url" placeholder="Offer URL (if applicable)" value="<?php echo $url; ?>"> 
     </div> 
     <div class="form-group col-md-12"> 
      <label class="col-md-8" for="image">Image <img src="../images/offers/<?php echo $image; ?>" alt="" style="width: 200px;" /></label> 
      <input id="image" class="form-control col-md-4" type="file" name="image"> 
     </div> 
     <div class="form-group col-md-12 pull-right"> 
      <button id="update" type="submit" name="update" class="btn btn-primary"><i class="glyphicon glyphicon-refresh"></i> Update</button> 
     </div> 
    </form> 

?! Ben hala php vb. Öğreniyorum, lütfen nazik olun, herhangi bir yardım çok takdir edilir.

UPDATE codes SET (title,description,redemption,start,expiry,textcode,terms,image,url) = (:title,:description,:redeem,:start,:exp,:code,:terms,:image,:url) WHERE id=:offerid 

UPDATE `codes` 
    SET `title` = :title, 
     `description` = :description, 
     `redemption` = :redeem, 
     `start` = :start 
     `expiry` = :expiry 
     `textcode` = :code 
     `terms` = :terms 
     `image` = :image 
     `url` = :url 
WHERE `id` = :offerid 

içine SQL Güncelleme sözdizimi here hakkında daha fazla bilgi: diğer çocuklar önce de belirtildiği gibi

+4

UPDATE sözdizimi http://dev.mysql.com/doc/refman/5.7/en/update.html adresindeki el kitabını okumak için biraz zaman harcayın. INSERT sözdizimi (belirli bir ölçüde). –

+0

"': id' => $ offerID" parametresini ekleyerek sorgunuzda bulunmuyorsunuz ... – Random

+1

Ayrıca, 'offerID' gönderilmekte olana göre undefined. –

cevap

1

Öncelikle, değişiklik, güncelleme deyimi yanlış sözdizimi vardır.

Ardından, execute() numaralı telefondan hata yaptınız. Aşağıdaki gibi :offerid içine :id değiştirme: Güncelleme

yanlış sözdizimi kullanan

$update->execute(array(
    ':title' => $updateTitle, 
    ':description' => $updateDesc, 
    ':redeem' => $updateRedeem, 
    ':start' => $updateStart, 
    ':exp' => $updateExpiry, 
    ':code' => $updateCode, 
    ':terms' => $updateTerms, 
    ':image' => $updateImage, 
    ':url' => $updateUrl, 
    ':offerid' => $offerID 
)); 
+1

Hata evet, ama bu düzeltmiyor. OP, UPDATE sözdizimi için kullanıyorsa, bugün için yeni PDO gurusu şeyleri öğrenmiş olurdum. –

+0

@ Fred-ii- Cevabım, kesinlikle eksik olan parametreye ilişkin hatayı, ciltleme verileriyle çözmesine yardımcı olmaktır. Ne demek onu tamir etmiyor? – Tomasz

+1

OP, UPDATE için doğru sözdizimi kullanmıyor. OP'ye yaptığım yorum, Saty'ın cevabı uygun sözdizimi de içerdiğinden, bunun için bir bağlantı içerir. –

1

O

$updateSql = "UPDATE codes SET title =:title, 
description =:description, 
redemption =:redeem, 
start =:start, 
expiry =:exp, 
textcode =:code, 
terms :=terms,image =:image, 
url =:url 
WHERE id=:id";// write id instead of offset because you are binding ':id'=>$offerID 

Kontrol cevaplar için http://dev.mysql.com/doc/refman/5.7/en/update.html

0

sayesinde olacaktır. Orijinal güncelleme sözdiziminiz, aslında sizin belirttiğiniz gibi oldu, diğer çözümlere bakarken onu değiştirdim ve değiştirmedim, ancak her iki şekilde de doğru sözdizimi olsa bile, hala aynı hatayı aldım.

Yanıtlarınızı gözden geçirerek, ': id' => $ offerID'm var ancak şunu kullandım: sql kodunda, açıkça güncellenmesi gereken offerid, bunu işaretlediğiniz için teşekkürler! Umarım bu sorunu çözer ...

İlgili konular