superblunt Posted June 25, 2008 Share Posted June 25, 2008 Hi I got one Mysql INSERT and one Mysql UPDATE that I want to do $sql1="INSERT INTO purchase (date, time, supplier, grade, mainitem, itemcode, itemmass, itemamount, gender, price) VALUES('$date','$time','$companyname','$grade','$mainitem','$itemcode','$itemmass','$itemamount','$gender','$itemprice')"; $sql2="UPDATE mainitem SET totalstock = 36 WHERE mainitem = '$mainitem'"; if($companyname=='' or $grade=='' or $mainitem=='' or $itemcode=='' or $itemmass=='' or $itemamount=='' or $gender=='' or $itemprice=='') { echo "<b>Please add all fields</b>"; exit; } if (!mysql_query($sql1)) { die('Error: ' . mysql_error()); } echo "1 record added"; if (!mysql_query($sql2)) { die('Error: ' . mysql_error()); } echo "1 record Updated"; when it is done it only adds the INSERT and not the update even though it shows bought echo's Quote Link to comment Share on other sites More sharing options...
scottybwoy Posted June 25, 2008 Share Posted June 25, 2008 You can't have single quotes round a $var Change $sql2 to : <?php $sql2="UPDATE mainitem SET totalstock = 36 WHERE mainitem = '" . $mainitem . "'"; ?> Quote Link to comment Share on other sites More sharing options...
bluejay002 Posted June 25, 2008 Share Posted June 25, 2008 though directly implying a variable inside a string is quite handy but i dont use it...personnal preference i guess. i usually use concatenation of values. Quote Link to comment Share on other sites More sharing options...
superblunt Posted June 25, 2008 Author Share Posted June 25, 2008 Thx allot but it still seems to only insert the INSERT and not the update Quote Link to comment Share on other sites More sharing options...
superblunt Posted June 25, 2008 Author Share Posted June 25, 2008 The variable is = to cow if i insert cow it works Quote Link to comment Share on other sites More sharing options...
superblunt Posted June 25, 2008 Author Share Posted June 25, 2008 o and the variable comes from a $_POST Quote Link to comment Share on other sites More sharing options...
superblunt Posted June 25, 2008 Author Share Posted June 25, 2008 I changed it input value to the item ID that seems to work Thx for you help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.