0

Im mainly a JavaScript guy and im building a library for a client and the library caches some data in MySQL per HTTP_REFERRER. If the data is different than it is on the server it updates the cache. I don't know what exactly I'm doing wrong but its saying there is a syntax error with this:

if(mysql_query("UPDATE `cache-test` (cache) SET ('".addslashes(preg_replace('/\s\s+/', ' ', $referrer['cache']))."') WHERE url = '".$referrer['current']."'",$con)){ echo "saved"; }
else { echo mysql_error($con); }

The error Im getting is:

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 '(cache) SET ('[{\"LatLng\":{\"Ba\":45.531124,\"Ca\":-122.68374699999998},\"InfoW' at line 1

The data being sent looks like (before being stripped and slashes added, of course):

[{"LatLng":{"Ba":45.531124,"Ca":-122.68374699999998},"InfoWindow":"\n        <address>1125 NW 12th Ave, Portland, OR</address>\n        <p>My first apartment</p>\n      ","originalAddress":"1125 NW 12th Ave, Portland, OR"},{"LatLng":{"Ba":45.5144501,"Ca":-122.67644239999998},"InfoWindow":"\n        <address>1230 SW 2nd Ave, Portland, OR</address>\n        <p>My 2nd apartment</p>\n      ","originalAddress":"1230 SW 2nd Ave, Portland, OR"},{"LatLng":{"Ba":45.748955,"Ca":-122.47959000000003},"InfoWindow":"\n        <address>17501 NE 188th Ct, Brush Prairie, WA</address>\n        <p>The first place I lived by my own</p>\n      ","originalAddress":"17501 NE 188th Ct, Brush Prairie, WA"},{"LatLng":{"Ba":45.756944,"Ca":-122.43575800000002},"InfoWindow":"\n        <address>18607 NE Erickson Rd, Brush Prairie, WA</address>\n        <p>Last place I lived with my parents</p>\n      ","originalAddress":"18607 NE Erickson Rd, Brush Prairie, WA"}

2 Answers 2

1

You don't have the field you wish to set:

UPDATE `cache-test` SET field_name = 'your huge val'
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! that was it. I thought it worked like insert where you define the fields like (a,b) ('a data','b data').
0

Replace addslashes with:

mysql_real_escape_string()

$cache = mysql_real_escape_string(preg_replace('/\s\s+/', ' ', $referrer['cache']));

mysql_query("UPDATE `cache-test`  
            SET (cache = '$cache') 
          WHERE url = '".$referrer['current']."'",$con));

Comments

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.