0

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

?>
2
  • I don't know PHP so I may be off on this, but it looks like you're deleting the very tuple from the database before you try to update it. As the tuple to be updated doesn't exist, you can't update it. What happens if you remove the deletion code? Commented Oct 6, 2012 at 5:08
  • 1
    @No'amNewman that code only executes when the delete action is triggered :) Commented Oct 6, 2012 at 5:10

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

10 Comments

zend reports: Function Name: mysql_query Function Arguments: 'UPDATE ads SET adcode = \'7000hghgvgh\\r\\nhbhbh\\r\\ndfdffg\\r\\ndggg\\r\\n\' WHERE ads_ID = \'8\' LIMIT 1'
that was the data i used. but it makes no sense why its not putting it in there, the database from zend is right
varchar(500) it works with the INSERT, but not with UPDATE if the datatype is wrong
code$doedit = "UPDATE ads SET adcode = '$newadcode' WHERE ads_ID = '$ID' LIMIT 1";code
weird indeed. i cant figure it out. Function Name: mysql_query Function Arguments: 'UPDATE ads SET adcode = \'7000sexhbhgbjhbjhbhj\' WHERE ads_ID = \'8\' LIMIT 1' its passing it per zend server
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.