0

When i update data using php mysql, got some issue, my code php code are here

$query = "UPDATE `wp_experience` SET 
                     `exp_from` ='". $exp_from."' ,
                     `exp_to` = '". $exp_to."' ,
                     `exp_title` = '". json_encode($exp_title)."',
                     `exp_desc` = '". json_encode($exp_desc)."' ,                               
                     `exp_cat` = '". $exp_cat."'                                
                     WHERE `id` =".$oldid;

it will produce data like,

UPDATE wp_experience SET exp_from ='2016-01-22 00:00:00' , exp_to = '2002-11-14 00:00:00' , exp_title = '{"en":" PSA Peugeot Citroën Automobiles, Mulhouse (F-68)","fr":"Technical Directué - FRENCH","de":"Responsable d'unité de maintenance"}', exp_desc = '{"en":" Test</p>","fr":" Test</p>","de":" H</p>"}' , exp_cat = '18' WHERE id =28

i got this issue,

1064 - 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 'unité de maintenance"}', exp_desc = '{"en":" Test</p>","fr":" Test</p' at line 1

How to fix this issue??

2
  • Responsable d'unité string breaks your query. use mysqli_real_escape_string() as much as you can in order to avoid such problems. Commented Mar 22, 2016 at 15:13
  • Please use prepared statements! Commented Mar 22, 2016 at 15:14

1 Answer 1

1

Some of your embedded strings breaks your query, so either use mysqli_real_escape_string() or prepared SQL statements:

$query = "
    UPDATE 
        wp_experience 
    SET 
        exp_from    = '" . $exp_from . "' ,  
        exp_to      = '" . $exp_to . "' , 
        exp_title   = '" . mysqli_real_escape_string($con, json_encode($exp_title)) . "',  
        exp_desc    = '" . mysqli_real_escape_string($con, json_encode($exp_desc)) . "' ,
        exp_cat     = '" . mysqli_real_escape_string($con, $exp_cat) . "'
    WHERE 
        id = " . $oldid;
Sign up to request clarification or add additional context in comments.

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.