2014-09-19 139 views
0
$id = 1; //temp 

$promoTitle = trim($_POST['promoTitle']); 
$imageURL = trim($_POST['imageURL']); 
$affLink = trim($_POST['affLink']); 
$couponCode = trim($_POST['couponCode']); 

$stmt = $db->prepare('UPDATE dashboard SET promoTitle=?, image=?, url=?, couponCode=? WHERE id=?'); 

$q = $stmt->bind_param('ssssi', $promoTitle, $imageURL, $affLink, $couponCode, $id); 

if($result = $db->query($q)){ 
    echo "updated"; 
}else{ 
    echo mysql_errno(); 
} 

卡住了半個小時,仍然找不到錯在哪裏。我沒有返回任何錯誤。我的表看起來像這樣http://i.imgur.com/snwloav.pngSQL更新查詢沒有執行,但沒有返回錯誤

+2

第三步準備,綁定,執行是'$ stmt-> execute()',而不是'$ db-> query()'。 – VMai 2014-09-19 10:08:21

回答

0

,你可以在MySQL從PHP用這個更新用

如果(isset($ _ POST [ '提交'])){ 嘗試{

  $id = 1; //temp 

     $promoTitle = trim($_POST['promoTitle']); 
     $imageURL = trim($_POST['imageURL']); 
     $affLink = trim($_POST['affLink']); 
     $couponCode = trim($_POST['couponCode']); 

     $stmt = $db->prepare('UPDATE dashboard SET promoTitle = :promoTitle, image = :image, url = :url, couponCode=:couponCode WHERE id =:id'); 
     $stmt->execute(array(
      ':promoTitle' => $promoTitle, 
      ':image' => $image, 
      ':url' => $url, 
      ':couponCode' => $couponCode,    
      ':id' =>$id       
     )); 

    //redirect to Your page page 
    header('Location: page.php?action=updated'); 
    exit; 
    } 

    catch(PDOException $e) { 
     echo $e->getMessage(); 
    } 

} 
+0

這是PDO,但OP使用mysqli。 – VMai 2014-09-19 10:22:04

0
$sql = "UPDATE Applicant SET phone_number=?, street_name=?, city=?, county=?, zip_code=?, day_date=?, month_date=?, year_date=? WHERE account_id=?"; 

$stmt = $db_usag->prepare($sql); 

$stmt->bind_param('sssssdddd', $phone_number, $street_name, $city, $county, $zip_code,  $day_date, $month_date, $year_date, $account_id); 
$stmt->execute(); 

if ($stmt->errno) { 
    echo "FAILURE!!! " . $stmt->error; 
} 
else echo "Updated {$stmt->affected_rows} rows"; 

$stmt->close(); 

php mysql bind-param, how to prepare statement for update query

相關問題