Question

Suddenly GD updated their MySQL servers last night from version 4.1 to 5.5. Now, I just realized that the algorithm to UPDATE or INSERT new rows of data into the table isn't working anymore. This is what I have (I've been using this same algorithm since 2007 with no issues, maybe now is a little outdated):

    if($error_msg == "") 
        {
            $sql = "UPDATE ".$db_prefix."cars SET
                stored='".$_POST['stored_year']."-".$_POST['stored_month']."-".$_POST['stored_day']."',
                year='".add_slashes($_POST['year'])."',
                model='".add_slashes($_POST['model'])."',
                type='".add_slashes($_POST['type'])."',
                typemodel='".add_slashes($_POST['typemodel'])."',
                bodystyle='".add_slashes($_POST['bodystyle'])."',
                engine='".add_slashes($_POST['engine'])."',
                trans='".add_slashes($_POST['trans'])."',
                drive='".add_slashes($_POST['drive'])."',
                color='".add_slashes($_POST['color'])."',
                condition='".add_slashes($_POST['condition'])."',
                millage='".add_slashes($_POST['millage'])."',
                vin='".add_slashes($_POST['vin'])."',
                price='".add_slashes(strip_out($_POST['price']))."',
                low='".add_slashes(strip_out($_POST['low']))."',
                high='".add_slashes(strip_out($_POST['high']))."',
                features='".$features_total."',
                comments='".add_slashes($_POST['comments'])."',
                mk_comment='".add_slashes($_POST['mk_comment'])."',
                title_page='".add_slashes($_POST['title_page'])."',
                certified='".add_slashes($_POST['certified'])."',
                sold='".add_slashes($_POST['sold'])."',
                sold_txt='".add_slashes($_POST['sold_txt'])."',
                se_index='".add_slashes($_POST['se_index'])."',
                one_owner='".add_slashes($_POST['one_owner'])."',
                special= '".$special."'
            WHERE id=".$_GET["id"];

    if(@mysql_query($sql)) die(header("Location: index.php?status=update"));
else
    $error_msg = "Record was not updated because of invalid data posted.";
}

I just get: "Record was not updated because of invalid data posted."

It is not showing any other error. I was just reading this post where it says that as from MySQL 5.0, you should include the database name before the table name $sql = "INSERT INTO database.table (columnOne, columnTwo)... but not sure.

If you have an idea of why this UPDATE isn't working anymore, I would really appreciate any help.


Edit: Taken from OP's comment: (for those wondering on the usage of the add_slashes() function).

add_slashes is inserted from the local functions file.

function add_slashes($string) { 
        if (!get_magic_quotes_gpc()) 
                return addslashes($string); 
        else
                return $string; 
}

Edit: I tried adding mysql_error() and I got:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'condition='good', millage='7087', vin='2BFKOPP25B5YR501', price' at line 12

Was it helpful?

Solution

condition is a reserved word http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html which is most likely a/the reason.

Try (using backticks around the word condition)

`condition`='".add_slashes($_POST['condition'])."',

Plus, if at all possible, try and use another word for the column name.


In past MySQL releases, condition was not a reserved word at the time which explains why it worked for you back then when you were using 4.1 and have since upgraded to 5.5.

condition became a reserved word as of version 5.0


Footnotes:

mysql_* functions deprecation notice:

http://www.php.net/manual/en/intro.mysql.php

This extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used. See also the MySQL API Overview for further help while choosing a MySQL API.

These functions allow you to access MySQL database servers. More information about MySQL can be found at » http://www.mysql.com/.

Documentation for MySQL can be found at » http://dev.mysql.com/doc/.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top