mysql UPDATE没有更新mysql表行

时间:2012-10-06 05:04:40

标签: php mysql

这是我第一次使用UPDATE(mysql)这段代码没有将更新发送到我的mysql数据库/ table / row。我在php.net上花了几个小时,但从我目前的水平或PHP知识中可以看出它的权利,因为我错了,他们我是哑巴=}。 我在mysql上启用了loggin - 没什么用处

这是来自ZEND服务器:所以它似乎正在传递,但它没有在mysql数据库中更新。 函数名称:mysql_query 功能参数: '更新广告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++;
}

?>

1 个答案:

答案 0 :(得分:5)

您缺少关闭双引号:

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

或者简单地写下这样的查询:

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

如果您只想更新一行,请使用LIMIT 1