2014-09-19 107 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

相关问题