php - MySQL error on inserting row into 2 separate tables -


i'm trying insert data 2 separate tables @ same time - getting following error:

you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'insert storetable (name, price, description, imagename, colors, sizes, sku,' @ line 1 

here's code:

// insert new store item & image database: $query = "begin; insert storetable(name, price, description, imagename, colors,  sizes, sku, category, dateadded) values ('". $newstoreitemname ."', '". $newstoreitemprice ."', '". $newstoreitemdescription ."', '". $newstoreitemimagename ."', '". $newstoreitemcolors ."',  '". $newstoreitemsizes ."',  '".$storenewitemsku."',   '".$newstoreitemcategory."', '".$storeitemdateadded."');  insert storecategoriestable (categoryname, datemodified) values('".$newstoreitemcategory ."', '". $storeitemdateadded."'); commit;";      // echo query statement see looks like:     echo "here's full query:<br/><br/>" .$query. "<br/><br/>";      $result = $mysqli->query($query); 

that echo statement shows looks correct mysql statement - not since i'm getting error:

begin; insert storetable (name, price, description, imagename, colors,  sizes, sku, category, dateadded) values ('shirt', '12.98', '100% cotton',  'tshirt.png', 'red, blue, black', 's, m, l', '88nnklb', 'childrens apparel', '2015-03-28 15:51:41'); insert storecategoriestable (categoryname, datemodified) values('childrens apparel', '2015-03-28 15:51:41'); commit; 

being i'm ios developer minimal mysql knowledge, i'd appreciate , this. thanks!

as security feature of php, able run 1 query @ time using mysqli::query(). recommend break these separate queries, making sure save properly, , committing them database. there great example can found here.

also: can take @ mysqli::multi_query, can achieve similar result.

i have 1 other thing mention here. please mindful of security! executing queries opens database sql injection attacks. highly recommend take @ this on how bind parameters queries. (this automagically escape needed ensure queries run without issue).


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -