0

I have a Mysql query as follows

$query = "UPDATE student_database SET fname='$fname',mname='$mname',lname='$lname',dob='$dob',Age='$age',Sex='$sex',Caste='$caste',dept='$dept', SSC%=$ssc , HSC%=$hsc, ATKTs=$atkt, Last_sem%=$lastsem, Aggregate%=$agg WHERE student_id=$id  ; ";

Some column names have a '%' sign in it. Mysql throws the following error when I execute it

Cannot execute.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 '%=79.6 , HSC%=81.83, ATKTs=5, Last_sem%=52.35, Aggregate%=53.6 WHERE student_id=' at line 1

Can't figure out the problem I have tried "\" , "#" , "%%" as escape characters but can't figure it out.

2 Answers 2

2

Wrap it in backticks to tell SQL that it's a column, does this work?

$query = "UPDATE student_database SET fname='$fname',mname='$mname',lname='$lname',dob='$dob',Age='$age',Sex='$sex',Caste='$caste',dept='$dept', `SSC%`=$ssc , `HSC%`=$hsc, ATKTs=$atkt, `Last_sem%`=$lastsem, `Aggregate%`=$agg WHERE student_id=$id  ; ";
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you KAVISIEGEL that helped. Can you please explain what the problem was?
In MySQL queries, in order to say that something is a column, it can be wrapped in backticks. Note how in the code above, it says `SSC%` where in your code, it says SSC%
1

Try wrapping the column names in backticks, e.g

`SSC%`=$ssc 

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.