php - update query problem -


hi have field "ammount" in mysql database have "varchar(50)" type. when insert data field e.g ammount= 4 kg ok when update field gives me following error.

error in query: update ingredients set ingredient_name='test recipe',ammount=4 gm ingredient_id='59'. have error in sql syntax; check manual corresponds mysql server version right syntax use near 'gm ingredient_id='59'' @ line 1

and query

 $query="update ingredients set ingredient_name='$ingredient',ammount=$ammount ingredient_id='$ingredient_id'";

1) correct spelling "amount".

2) you should not using variable interpolation sql query. unsafe. use prepared statement.

3) didn't put quotes around $amount when defining $query, don't end in final substituted query string. closely @ error message: shows query sql tried process. notice how says ammount=4 gm? can't handle that, because there no quotes.

if use prepared statements supposed to, quoting takes care of itself.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -