2013-07-25 16 views
0

我想通過PHP更新文本,我可以查詢實際的文本存儲在我的SQL和顯示在輸入框,當我嘗試更新什麼都沒有改變, 我把回聲變量,看它是否工作,我可以閱讀我的數據庫在我的確認頁新的文本,但仍然沒有改變,我盡我直接更新MySQL和它的工作 這裏是我的代碼可以更新我的文本形式到MySQL與PHP

enter code here 
<?php 
include "../storescripts/connect_to_mysql.php"; 
// Parse the form data and add inventory item to the system 
if (isset($_POST['thisID'])) { 
    $id = $_POST['thisID']; 
$name = 'names'; 
$textes = $_POST['textes']; 
// See if that product name is an identical match to another product in the system 
$sql = mysql_query("UPDATE library SET name='$name',textes='$textes'WHERE id='$id");             
echo ''.$id.' New text is online, cliquer <a href="inventory_list.php">ici</a>.'; 

exit(); 

} 
?> 
and my form 
    <form action="text_edit.php" enctype="multipart/form-data" name="myForm" id="myform"  method="post"> 
    <table width="90%" border="0" cellspacing="0" cellpadding="6"> 
    <tr> 
    <td width="20%" align="right">Title</td> 
    <td width="80%"><label> 
     <input name="name" type="text" id="name" size="64" value="<?php echo $name; ?>" /> 
    </label></td> 
    </tr>  
    </form> 
</td> 
    </tr> 
    <?php echo ''.$targetID.' ';?> 
    <tr> 
    <td align="right">Text</td> 
    <td><label> 
     <textarea name="textes" id="textes" cols="64" rows="5"><?php echo $textes; ?>  </textarea> 
    </label></td> 
    </tr> 
    <tr> 

    <td>&nbsp;</td> 
    <td ><label> 
     <input name="thisID" type="hidden" value="<?php echo $targetID; ?>" /> 
     <input type="submit" name="button" id="btnsaveedit" value="Save Changes" /> 
    </label>&nbsp;   
+0

在查詢中有語法錯誤。另外,如果你的文本包含單引號呢? –

+0

這不是一個我知道的關於安全問題的最終文件,我歪曲了很多代碼,我覺得我要瘋了...只是kiddin – gekim360

回答

0
$sql = mysql_query("UPDATE library SET name='$name',textes='$textes'WHERE id='$id"); 

insted

$ sql = mysql_query(「UPD ATE庫SET name ='$ name',textes ='$ textes'WHERE id = $ id「);

+0

我的空白空間創建時,它的一個職位,它的晚,這是我的第二個在1年的時間我發佈它,但感謝您的回答 – gekim360

+0

找到它我忘記了$ id後的單引號 – gekim360

0

所有你必須確保$ targetID變量有一個值,然後</form>標記必須在所有表單域結束時關閉。

$sql = "UPDATE library SET name='".$name."',textes='".$textes."' WHERE id = '".$id."'"; 
mysql_query($sql); 
+0

感謝您的回答是所有的形式是接近的,你可以看到上面我把echo $ targetID,我看到它時我加載頁面 – gekim360

+0

找到它,我忘記$ id後的單引號 – gekim360