Jump to content

Problem with a form


Shadowing

Recommended Posts

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'])."'");

}}} ?> 

Link to comment
https://forums.phpfreaks.com/topic/254334-problem-with-a-form/
Share on other sites

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'];
}}}

?> 

Link to comment
https://forums.phpfreaks.com/topic/254334-problem-with-a-form/#findComment-1304138
Share on other sites

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/254334-problem-with-a-form/#findComment-1304142
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.