I am trying to update the data in a row of a table which by specific user ID. But I am receiving syntax error. Could anyone tell me what's the wrong in the syntax or I miss something ?
Result of an echo statement --->
UPDATE activitymeter SET totaltimes = 4, tna_wd = 1, tnm_wd = 10, tna_we = 10, tnm_we = 10, mvpa_wd = 2, mvpa_we = 5, week_diff = -3, tailor_advice= Your weekday activity level is below the recommended levels but it looks as though this is improved on a weekend. WHERE user_id = 2227904 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 'weekday activity level is below the recommended levels but it looks as though th' at line 10
I always use more complete syntax (include all back-ticks for table names, etc) like so:
$intotable = "UPDATE `activitymeter` SET `update_totaltimes` = '".$totalactivity."', `update_tna_wd` = '".$timeweekday."', `update_tnm_wd` = '".$totalweekday."', `update_tna_we` = '".$timeweekend."', `update_tnm_we` = '".$totalweekend."', `update_mvpa_wd` = '".$mvpaweekday."', `update_mvpa_we` = '".$mvpaweekend."', `update_week_diff` = '".$dayenddifference."', `update_tailor_advice` = '".$tailoradvice."', `timestamp_column` = '".$tsnow."' WHERE `user_id` = '".$userid."';";
From the above printed sql query, the type of tailor_advice
field is may be text or varchar, so the value must put inside double quotes or single quotes.