0

这是我第一次使用 UPDATE (mysql) 此代码不会将更新发送到我的 mysql 数据库/表/行。我在 php.net 上花了几个小时,但从我目前的水平或 php 知识来看,这是正确的,因为我错了,所以我很笨 =}。我在 mysql 上打开了登录 - 没什么用

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

?>
4

1 回答 1

5

您缺少右双引号:

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

或者干脆这样写你的查询:

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

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

于 2012-10-06T05:07:16.247 回答