简体   繁体   中英

mysql UPDATE not updating the mysql table row

This is my first time with UPDATE (mysql) this code isn't send the updates to my mysql database/table/row. I spent hours on php.net , but from what I can see at my current level or php knowledge its right and since I'm wrong, them I' dumb =}. I turned loggin on mysql - nothing useful

This is from ZEND server: So it appears to be passing, but it is not updating in the mysql database. Function Name: mysql_query Function Arguments: 'UPDATE ads SET adcode = \\'7000sbjhbjhbhjb\\' WHERE ads_ID = 8'

any pointers/help is much appreciated.

<?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++;
}

?>

You are missing closing double quotes :

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

Or simply write your query like this :

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

Use LIMIT 1 if you want to update only a single row

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM