Shadowing Posted January 4, 2012 Share Posted January 4, 2012 Im a having a problem and im thinking maybe i cant do it with php and will have to look into java script I have several If statements but will only display two of them below. both inputs run on the same button $_POST['build'] the first if statement updates $naqahdah in the database. Its a number being subtracted. I need the 2nd if statement to grab the new updated naqahdah field in the database before the script reads it. <?php if ($_POST['build']) { if ($_POST['homes']) { if ($naqahdah < $cost_homes) { }else{ mysql_query("UPDATE systems SET homes= $homes + '".mysql_real_escape_string($_POST['homes'])."' WHERE address = '".mysql_real_escape_string($_GET['planet'])."' AND id = '".($_SESSION['user_id'])."'"); mysql_query("UPDATE systems SET naqahdah= $naqahdah - $cost_homes WHERE address = '".mysql_real_escape_string($_GET['planet'])."' AND id = '".($_SESSION['user_id'])."'"); }}} if(isset($_POST['build'])) { if($_POST['naqahdah_mines']) { if ($naqahdah < $cost_naqahdah_mines) { }else{ mysql_query("UPDATE systems SET naqahdah_mines= $naqahdah_mines + '".mysql_real_escape_string($_POST['naqahdah_mines'])."' WHERE address = '".mysql_real_escape_string($_GET['planet'])."' AND id = '".($_SESSION['user_id'])."'"); mysql_query("UPDATE systems SET naqahdah= $naqahdah - $cost_naqahdah_mines WHERE address = '".mysql_real_escape_string($_GET['planet'])."' AND id = '".($_SESSION['user_id'])."'"); }}} ?> Quote Link to comment https://forums.phpfreaks.com/topic/254334-problem-with-a-form/ Share on other sites More sharing options...
requinix Posted January 4, 2012 Share Posted January 4, 2012 $naqahdah = $naqahdah - $cost_homes; Quote Link to comment https://forums.phpfreaks.com/topic/254334-problem-with-a-form/#findComment-1304107 Share on other sites More sharing options...
Shadowing Posted January 4, 2012 Author Share Posted January 4, 2012 thanks for the reply requinix I forgot to mention not all form inputs will always be used so its a form of 12 inputs and not all fields will be filled out always. its a form where im buying items with $naqahdah Quote Link to comment https://forums.phpfreaks.com/topic/254334-problem-with-a-form/#findComment-1304115 Share on other sites More sharing options...
requinix Posted January 4, 2012 Share Posted January 4, 2012 So update $nwhatever every time it gets adjusted in the database. That way you don't have to keep looking it up. Quote Link to comment https://forums.phpfreaks.com/topic/254334-problem-with-a-form/#findComment-1304120 Share on other sites More sharing options...
Shadowing Posted January 4, 2012 Author Share Posted January 4, 2012 awesome i didnt even think it worked like that lol. ok so I added a select query to update $naqahdah after the update query in the if statements. now my form only lets me update one input at a time. not sure why its doing that. Is this how you meant to update it? just reselect it? <?php if(isset($_POST['build'])) { if(!empty($_POST['homes'])) { if ($naqahdah < $cost_homes) { }else{ mysql_query("UPDATE systems SET homes= $homes + '".mysql_real_escape_string($_POST['homes'])."' WHERE address = '".mysql_real_escape_string($_GET['planet'])."' AND id = '".($_SESSION['user_id'])."'"); mysql_query("UPDATE systems SET naqahdah= $naqahdah - $cost_homes WHERE address = '".mysql_real_escape_string($_GET['planet'])."' AND id = '".($_SESSION['user_id'])."'"); $naq_update2 = "SELECT * FROM systems WHERE address = '" .($_GET['planet'])."' AND id= '" .($_SESSION['user_id'])."'"; $naq_update1 = mysql_query($naq_update2) or die(mysql_error()); $naqahdah = $naq_update1['naqahdah']; }} if(!empty($_POST['naqahdah_mines'])) { if ($naqahdah < $cost_naqahdah_mines) { }else{ mysql_query("UPDATE systems SET naqahdah_mines= $naqahdah_mines + '".mysql_real_escape_string($_POST['naqahdah_mines'])."' WHERE address = '".mysql_real_escape_string($_GET['planet'])."' AND id = '".($_SESSION['user_id'])."'"); mysql_query("UPDATE systems SET naqahdah= $naqahdah - $cost_naqahdah_mines WHERE address = '".mysql_real_escape_string($_GET['planet'])."' AND id = '".($_SESSION['user_id'])."'"); $naq_update2 = "SELECT * FROM systems WHERE address = '" .($_GET['planet'])."' AND id= '" .($_SESSION['user_id'])."'"; $naq_update1 = mysql_query($naq_update2) or die(mysql_error()); $naqahdah = $naq_update3['naqahdah']; }}} ?> Quote Link to comment https://forums.phpfreaks.com/topic/254334-problem-with-a-form/#findComment-1304138 Share on other sites More sharing options...
Shadowing Posted January 4, 2012 Author Share Posted January 4, 2012 ahh i dont know what I was thinking lol thanks so much I see what you mean now and it works just update it with this like you said. $naqahdah = $naqahdah - $cost_homes; now i need to see if i can get a header to work with this so it shows the new data on screen refresh with using the no cache on broswer Quote Link to comment https://forums.phpfreaks.com/topic/254334-problem-with-a-form/#findComment-1304142 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.