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 Link to comment https://forums.phpfreaks.com/topic/111810-noob-help-please/ 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 . "'"; ?> Link to comment https://forums.phpfreaks.com/topic/111810-noob-help-please/#findComment-573959 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. Link to comment https://forums.phpfreaks.com/topic/111810-noob-help-please/#findComment-573963 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 Link to comment https://forums.phpfreaks.com/topic/111810-noob-help-please/#findComment-573970 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 Link to comment https://forums.phpfreaks.com/topic/111810-noob-help-please/#findComment-573972 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 Link to comment https://forums.phpfreaks.com/topic/111810-noob-help-please/#findComment-573973 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 Link to comment https://forums.phpfreaks.com/topic/111810-noob-help-please/#findComment-573974 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.