php - I have an error With Mysql Query -
$sql="update item_master set department=$dept,make=$make,vat=$vat,cost=$mrp,packing=$pack,unit=$unit,exp_date=$ex,stock=$stock,description=$desc item_code=$id"; mysql_select_db('pds', $conn); $result = mysql_query($sql);
and error :
-id= 1dept=ayurvedicmake=arihantname=sample2vat=4mrp=100pack=1*100could not run query: have error in sql syntax; check manual corresponds mysql server version right syntax use near 'where item_code= 1' @ line 2
there few things wrong here.
seeing many of variables stand @ being strings, required quoted.
another thing spotted there no space between description=$desc
, where
.
for example: if $desc
defined testing
, mysql interpreting as:
description=testingwhere item_code=$id
which explain error few reasons, unquoted variable , missing space.
change code following.
$sql="update item_master set department = '$dept', make = '$make', vat = '$vat', cost = '$mrp', packing = $pack, unit = '$unit', exp_date= '$ex', stock = '$stock', description = '$desc' item_code=$id";
sidenote: it's best using uppercase letters functions , clauses. helps differentiate them rest of code.
plus, code highly prone sql injection. consider using prepared statements, or sanitize code now, until do.
another important note.
if you're still having problems, there may characters being inserted mysql may complaining about. therefore, need escape data.
example, , rest others:
mysql_real_escape_string($dept);
- double check column types matches data, , lengths also.
references:
Comments
Post a Comment