2012-10-06 89 views
0

這是我第一次用UPDATE(mysql)這段代碼沒有發送更新到我的mysql數據庫/表/行。我花了幾個小時在php.net上,但從我目前的水平或php知識中可以看到它的權利,並且因爲我錯了,他們我'啞'=}。 我在mysql上啓用了登錄 - 沒有用的mysql UPDATE不更新mysql錶行

這是來自ZEND服務器:所以它似乎是通過,但它不在mysql數據庫中更新。 功能名稱:請求mysql_query 函數參數: 'UPDATE廣告SET adcode = \' 7000sbjhbjhbhjb \」 WHERE ads_ID = 8'

任何指針/幫助深表感謝。

<?php 
require 'config.php'; 

// Report all Errors 
//error_reporting(-1); 
//ini_set('display_errors','On'); 

//connect to DB 
mysql_connect("$host", "$db_user", "$db_password"); 
mysql_select_db("$db_name"); 
    $query = "SELECT * FROM ads"; 
    $result = mysql_query($query); 
    $num = mysql_numrows($result); 

echo "<h1><center>AD's Currently Available</center></h1><br /><br />"; 

$i=0; 
while ($i < $num) { 
    $ID = mysql_result($result,$i,"ID"); 
    $adname = mysql_result($result,$i,"adname"); 
    $currentadcode = mysql_result($result,$i,"adcode"); 

// Delete AD item by ID number 
$action = (isset($_REQUEST['action'])); 
if ($_GET['action'] == "deletead") { // remove AD 
    mysql_query("DELETE FROM ads where ID = '$_GET[IDnum]'"); 
    $i=$i++; 
    header("Location: " . $_SERVER['PHP_SELF']); 
} 

$letknown = "<b>AD removed</b><br />"; 

**// Edit AD code 
if (isset($_POST['editad' . $ID])) { 
    $newadcode = mysql_real_escape_string($_POST['adcode' . $ID]); 
    $doedit = "UPDATE ads SET adcode = '" . $newadcode . "' WHERE ads_ID = " . $ID; 
    $updatead = mysql_query($doedit); 
    header("Location: " . $_SERVER['PHP_SELF']);** 

} 
$letknown = "<b>Ad Edited</b><br />"; 

    echo "<b>$ID : $adname</b><br /><a href=\"?action=deletead&IDnum=$ID\">Delete Ad</a><br /><br />\n"; 
    echo "Preview :<br /><div class=\"adcode\">$currentadcode</div><br /> \n"; 
    echo "<br />\n"; 
    echo "<form action=\"displayads.php\" name=\"addAD$ID\" method=\"post\">\n"; 
    echo "AD code (can be any type of script) text link, javascript or banner :<br />\n"; 
    echo "Code :<br /><textarea name=\"adcode$ID\" wrap=\"physical\" cols=\"60\" rows=\"5\" onKeyDown=\"textCounter(document.addAD$ID.adcode$ID,document.addAD$ID.remLen$ID,5000)\" onKeyUp=\"textCounter(document.addAD$ID.adcode$ID,document.addAD$ID.remLen$ID,5000)\">$currentadcode</textarea>"; 
    echo "<br /><input readonly type=\"text\" name=\"remLen$ID\" size=\"3\" maxlength=\"3\" value=\"5000\">Characters Left \n"; 
    echo "**<input type=\"submit\" name=\"editad$ID\" value=\"Edit AD Code\">**</form>\n"; 
    echo "<br /><hr />"; 

$i++; 
} 

?> 
+0

我不知道PHP,所以我可能會關閉它,但它看起來像你是d在嘗試更新數據庫之前,先從數據庫中選擇一個元組。由於要更新的​​元組不存在,因此無法對其進行更新。如果刪除刪除代碼會發生什麼? –

+1

@ No'amNewman代碼只在觸發刪除操作時執行:) –

回答

5

你缺少右雙引號:

$doedit = "UPDATE ads SET adcode = '" . $newadcode . "' WHERE ads_ID = '". $ID."'"; 

或者乾脆寫這樣的查詢:

$doedit = "UPDATE ads SET adcode = '$newadcode' WHERE ads_ID = '$ID'"; 

使用極限1,如果你想更新只有一行

+0

zend報告: 函數名稱:mysql_query 函數參數: 'UPDATE ads SET adcode = \'7000hghgvgh \\ r \\ nhbhbh \\ r \ \ ndfdffg \\ r \\ ndggg \\ r \\ n \'WHERE ads_ID = \'8 \'LIMIT 1' – Caiapfas

+0

這是我使用的數據。但爲什麼不把它放在那裏,zend的數據庫是正確的 – Caiapfas

+0

'adcode'字段的數據類型是什麼? –