2015-02-24 88 views
1

好吧,我儘量讓與PDO MYSQL的更新查詢,以便學習如何讓它工作,然後做一個功能,使其更有效地動態PHP MYSQL PDO查詢不更新[無錯誤返回]

問題是不起作用,我做所有的日誌文件允許我調試和個人回報,我alsy修復任何導航器告訴&即使與螢火蟲

任何想法可以是什麼?

任何建議,問題,意見或任何形式的回答不是幫助改善,澄清或回答的問題將大大aprreciated

在此先感謝

<?php 
include('conexion.php'); 
session_start(); 


$idf = $_POST['Id_Msg']; 
$ids = (int) $idf; 

var_dump($ids); 
    echo '<br /><br />'; 
var_dump($_FILES); 

echo '<br /><br />'; 
var_dump($_POST); 
echo '<br /><br />'; 

    $wlq = -1; 

if($_POST['Title']) { 
    $wlq++; 
} 
if($_POST['Prelude']) { 
    $wlq++; 
} 

if($_POST['Text']) { 
    $wlq++; 
} 

if($_POST['NOMBR1']) { 
    $wlq++; 
} 

if($_POST['NOMBR2']) { 
    $wlq++; 
} 

if($_POST['NOMBR3']) { 
    $wlq++; 
} 

if($_POST['NOMBR4']) { 
    $wlq++; 
} 

if($_POST['REGIN']) { 
    $wlq++; 
} 

if($_POST['CTGRY']) { 
    $wlq++; 
} 

if(!empty($_FILES['RutIm']['name'])) { 
    $wlq++; 
    echo 'me esta detectando visteh!'; 
} 

echo "Asignado es: ".$wlq.'<br /><br />'; 

$qls = "UPDATE `cmtmplo` SET"; 

if($_POST['Title']) { 
    if($wlq > 0){ 
    $qls .=" `Title` = :Title , "; 
    $wlq--; 
    } else { 
    $qls .=" `Title` = :Title"; 
    } 
} 

if($_POST['Prelude']) { 
    if($wlq > 0){ 
    $qls .=" `Prelude` = :Prelude , "; 
    $wlq--; 
    } else { 
    $qls .=" `Prelude` = :Prelude"; 
    } 
} 

if($_POST['Text']) { 
    if($wlq > 0){ 
    $qls .=" `Text` = :Text , "; 
    $wlq--; 
    } else { 
    $qls .=" `Text` = :Text"; 
    } 
} 

if($_POST['NOMBR1']) { 
    if($wlq > 0){ 
    $qls .=" `NOMBR1` = :NOMBR1 , "; 
    $wlq--; 
    } else { 
    $qls .=" `NOMBR1` = :NOMBR1"; 
    } 
} 

if($_POST['NOMBR2']) { 
    if($wlq > 0){ 
    $qls .=" `NOMBR2` = :NOMBR2 , "; 
    $wlq--; 
    } else { 
    $qls .=" `NOMBR2` = :NOMBR2"; 
    } 
} 

if($_POST['NOMBR3']) { 
    if($wlq > 0){ 
    $qls .=" `NOMBR3` = :NOMBR3 , "; 
    $wlq--; 
    } else { 
    $qls .=" `NOMBR3` = :NOMBR3"; 
    } 
} 

if($_POST['NOMBR4']) { 
    if($wlq > 0){ 
    $qls .=" `NOMBR4` = :NOMBR4 , "; 
    $wlq--; 
    } else { 
    $qls .=" `NOMBR4` = :NOMBR4"; 
    } 
} 

if($_POST['REGIN']) { 
    if($wlq > 0){ 
    $qls .=" `REGIN` = :REGIN , "; 
    $wlq--; 
    } else { 
    $qls .=" `REGIN` = :REGIN"; 
    } 
} 

if($_POST['CTGRY']) { 
    if($wlq > 0){ 
    $qls .=" `CTGRY` = :CTGRY , "; 
    $wlq--; 
    } else { 
    $qls .=" `CTGRY` = :CTGRY"; 
    } 
} 

if(!empty($_FILES['RutIm']['name'])) { 
    if($wlq > 0){ 
    $qls .=" `RutIm` = :RutIm , "; 
    $wlq--; 
    } else { 

    } 
} 

$qls .= " WHERE 'Id_Msg' = :ids"; 
echo $qls; 
$stmt = $con->prepare($qls); 
$stmt->bindValue(':ids', $ids); 

if(isset($_POST['Title']) && !empty($_POST['Title'])) { 
    $stmt->bindValue('Title', $_POST['Title']); 
} 

if(isset($_POST['Prelude']) && !empty($_POST['Prelude'])) { 
    $stmt->bindValue('Prelude', $_POST['Prelude']); 
} 

if(isset($_POST['Text']) && !empty($_POST['Text'])) { 
    $stmt->bindValue('Text', $_POST['Text']); 
} 

if(isset($_POST['NOMBR1']) && !empty($_POST['NOMBR1'])) { 
    $stmt->bindValue('NOMBR1', $_POST['NOMBR1']); 
} 

if(isset($_POST['NOMBR2']) && !empty($_POST['NOMBR2'])) { 
    $stmt->bindValue('NOMBR2', $_POST['NOMBR2']); 
} 

if(isset($_POST['NOMBR3']) && !empty($_POST['NOMBR3'])) { 
    $stmt->bindValue('NOMBR3', $_POST['NOMBR3']); 
} 

if(isset($_POST['NOMBR4']) && !empty($_POST['NOMBR4'])) { 
    $stmt->bindValue('NOMBR4', $_POST['NOMBR4']); 
} 

if(isset($_POST['REGIN']) && !empty($_POST['REGIN'])) { 
    $stmt->bindValue('REGIN', $_POST['REGIN']); 
} 

if(isset($_POST['CTGRY']) && !empty($_POST['CTGRY'])) { 
    $stmt->bindValue('CTGRY', $_POST['CTGRY']); 
} 

if(!empty($_FILES['RutIm']['name'])) { 
    $carpeta = "images/"; 
    opendir($carpeta); 
    $destiny = $carpeta.$_FILES['RutIm']['name'].".jpg"; 
    copy($_FILES['RutIm']['tmp_name'],$destiny); 
    $skr=$_FILES['RutIm']['name']; 
    $stmt->bindValue('RutIm', $skr);  
} 
$stmt->execute(); 
?> 

回聲$ QLS輸出的

UPDATE cmtmplo SET Title = :Title , REGIN = :REGIN , CTGRY = :CTGRY WHERE 'Id_Msg' = :ids

+0

究竟什麼是你的'回聲$ QLS;'輸出? – Alex 2015-02-24 18:03:53

+0

它取決於哪些部分我添加文本和其他什麼不是,但這是什麼返回與當前測試更新'cmtmplo' SET'標題'=:標題,'REGIN' =:REGIN,'CTGRY' =:CTGRY WHERE' Id_Msg'=:ids – user57129 2015-02-24 20:37:35

+0

那麼請告訴我'$ qls'的輸出? – Alex 2015-02-24 20:46:21

回答

1

你需要更改的所有標籤一樣'Title'':Title'

if(isset($_POST['Title']) && !empty($_POST['Title'])) { 
    $stmt->bindValue(':Title', $_POST['Title']); 
} 

.... 

等等...您綁定的所有參數必須以:

所以現在我們可以看到,你應該改變

$qls .= " WHERE 'Id_Msg' = :ids"; 

$qls .= " WHERE `Id_Msg` = :ids"; 

apostrophs蜱

+0

嘗試,你沒事,但它仍然不更新 – user57129 2015-02-24 20:39:26

+0

冒號是不需要 – meda 2015-02-24 21:12:23

+0

@ user57129所以現在我們可以看到你正在改變'$ qls。=「WHERE'Id_Msg'=:ids」;'到'$ qls。=「WHERE \'Id_Msg \'=:ids」;'spostrophs嘀嗒 – Alex 2015-02-24 21:25:07

2

PHP PDO提供了一種很好的查找方式看看查詢可能有什麼問題。 PDOStatement::execute()默認情況下只返回true或false。它不會返回任何具體的細節。

有關詳細的錯誤信息,您可以使用:

var_dump($con->errorInfo()); 

有關詳細信息,請參閱文檔頁面:

+0

另外'$ dbh-> setAttribute(PDO :: ATTR_ERRMODE,PDO :: ERRMODE_EXCEPTION);'會啓用異常基於錯誤的處理,如果這種事情變成你的曲柄。 – Sammitch 2015-02-24 21:26:21

+0

你可以在這個代碼的情況下實例嗎?,我不太習慣使用這個錯誤處理程序,謝謝 – user57129 2015-02-24 21:31:32

+0

@ user57129在你的代碼中,你可以做一些事情:'if($ stmt-> execute()){echo'Successfully updated'} else {print_r( $ con> errorInfo())}' – 2015-02-24 22:07:08