Jump to content

Recommended Posts

Evening PHP Freaks,

 

I have 3 mains sections on my webpage, Left panel, content and right panel. The problem is in the way I have to include them, and the way the CSS works in floating them. I have them all set to float left, so I have to include them like this:

<?php
include("leftpanel.php");
?>

<?php
include("content.php");
?>

<?php
include("rightpanel.php");
?>

 

but then when I do a mysql query in content by POSTing to content.php, it doesn't display the new database results in content.php or leftpanel.php because of the way it is included. Is there a way to make leftpanel.php include after content.php, but still make the CSS think it has been included first?? or something like that??

 

any help is greatly appreciated!

 

Regards ACE

Link to comment
https://forums.phpfreaks.com/topic/87187-solved-include-order-is-the-wrong-order/
Share on other sites

basically I have index.php setup like this:

<?php
include_once('leftnav.php');
?>

<div id="content">

<?php
	switch ($_GET['page']) {
		default:
		case "home":
			require_once ("lib/home.php");
			break;
		case "bank":
			require_once ("lib/bank.php");
			break;
	}// end switch
?>

</div>

<?php
include_once('rightnav.php');
?>

 

with this CSS for leftnav.php(#nav in CSS), bank.php and home.php(#content) and for rightnav.php(#ads)

#nav,#content,#ads {float:left}

 

and heres bank.php with the queries:

<?php // Bank
// error_reporting(E_ALL);
player_session();

// player info to be used
$player_accountid = player_table("id");
$player_bank = player_table("bank");
$player_money = player_table("money");

// POST variables
$amount_deposit = addslashes($_POST['amount_deposit']);
$amount_withdraw = addslashes($_POST['amount_withdraw']);


// check if its a deposit or withdraw

if(isset($_POST['amount_deposit'])) 
{
if(is_numeric($amount_deposit)) 
{

	if($amount_deposit > $player_money) { $msg = "You do not have that much money on hand"; die($msg); }
		else 
		{

		// work out new money
		$new_money = $player_money - $amount_deposit;

		// work out money in bank
		$bank_money = $player_bank + $amount_deposit;

		// update money and bank
		$sql = "UPDATE `cf_users` SET `money` = '$new_money', `bank` = '$bank_money' WHERE `id`='" . $player_accountid . "' LIMIT 1";
		$rs = mysql_query($sql) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error());

		}

}
unset($amount_deposit);
}
elseif(isset($_POST['amount_withdraw'])) 
{
if(is_numeric($amount_withdraw)) 
{
	if($amount_withdraw > $player_bank) { $msg = "You do not have that much money in the bank"; die($msg); }
		else 
		{

		// work out new money
		$new_money = $player_money + $amount_withdraw;

		// work out money in bank
		$bank_money = $player_bank - $amount_withdraw;

		// update money and bank
		$sql = "UPDATE `cf_users` SET `money` = '$new_money', `bank` = '$bank_money' WHERE `id`='" . $player_accountid . "' LIMIT 1";
		$rs = mysql_query($sql) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error());

		}
}
unset($amount_withdraw);
}



?>


<table align="center" class = "standard">


<tr>
<td colspan="4">
<center><b>Bank</b></center>
</td>
</tr>

<?php if(isset($msg)) { ?>

<tr>
<td colspan="4">
<center><font color="red"><?php echo $msg; ?></font></center>
</td>
</tr>

<?php unset($msg); } ?>

<tr>
<td>Money on Hand</td>  
<td>$<?php echo number_format($player_money); ?></td>
<td>Money in the Bank</td> 
<td>$<?php echo number_format($player_bank); ?></td>
</tr>

<tr>
<td colspan="4"></td>
</tr>

<form name="deposit" action="index.php?page=bank" method="post">
<tr>
<td><b>Deposit</b></td>
<td colspan="2"> <center> <input type="submit" value="Deposit"> </center> </td>
<td> <center> <input type="text" size="15" name="amount_deposit" value="<?=$player_money?>"> </center> </td>
</tr>
</form>

<form name="withdraw" action="index.php?page=bank" method="post">
<tr>
<td><b>Withdraw</b></td>
<td colspan="2"> <center> <input type="submit" value="Withdraw"> </center> </td>
<td> <center> <input type="text" size="15" name="amount_withdraw" value="<?=$player_bank?>"> </center> </td>
</tr>
</form>

</table>

 

 

Evening PHP Freaks,

 

I have 3 mains sections on my webpage, Left panel, content and right panel. The problem is in the way I have to include them, and the way the CSS works in floating them. I have them all set to float left, so I have to include them like this:

<?php
include("leftpanel.php");
?>

<?php
include("content.php");
?>

<?php
include("rightpanel.php");
?>

 

you can include your files at the top and use a variable to output what you want.. notice that when you inlude the file it like you merge the content of that file in your current page

 

but then when I do a mysql query in content by POSTing to content.php, it doesn't display the new database results in content.php or leftpanel.php because of the way it is included. Is there a way to make leftpanel.php include after content.php, but still make the CSS think it has been included first?? or something like that??

 

any help is greatly appreciated!

 

Regards ACE

Evening PHP Freaks,

 

I have 3 mains sections on my webpage, Left panel, content and right panel. The problem is in the way I have to include them, and the way the CSS works in floating them. I have them all set to float left, so I have to include them like this:

<?php
include("leftpanel.php");
?>

<?php
include("content.php");
?>

<?php
include("rightpanel.php");
?>

 

 

 

but then when I do a mysql query in content by POSTing to content.php, it doesn't display the new database results in content.php or leftpanel.php because of the way it is included. Is there a way to make leftpanel.php include after content.php, but still make the CSS think it has been included first?? or something like that??

 

any help is greatly appreciated!

 

Regards ACE

 

you can include your files at the top and use a variable to output what you want..  when you include the file its like you merge the content of that file in your current page

sorry.... edited..

 

I'm trying to display the new database information, by using the variables I used in the mysql UPDATE query. But I'm having alittle trouble using the isset() and unset() functions to work out if the variables have been set or not(as I use forms to POST the database back to the same page).

 

here's my latest code for content.php:

<?php // Bank
// error_reporting(E_ALL);
player_session();

// player info to be used
$player_accountid = player_table("id");
$player_bank = player_table("bank");
$player_money = player_table("money");

// POST variables
$amount_deposit = addslashes($_POST['amount_deposit']);
$amount_withdraw = addslashes($_POST['amount_withdraw']);


// check if its a deposit or withdraw

if(isset($_POST['amount_deposit'])) 
{
if(is_numeric($amount_deposit)) 
{

	if($amount_deposit > $player_money) { $msg = "You do not have that much money on hand"; die($msg); }
		else 
		{

		// work out new money
		$new_money = $player_money - $amount_deposit;

		// work out money in bank
		$bank_money = $player_bank + $amount_deposit;

		// update money and bank
		$sql = "UPDATE `cf_users` SET `money` = '$new_money', `bank` = '$bank_money' WHERE `id`='" . $player_accountid . "' LIMIT 1";
		$rs = mysql_query($sql) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error());

		}

}
//unset($amount_deposit);
}
elseif(isset($_POST['amount_withdraw'])) 
{
if(is_numeric($amount_withdraw)) 
{
	if($amount_withdraw > $player_bank) { $msg = "You do not have that much money in the bank"; die($msg); }
		else 
		{

		// work out new money
		$new_money = $player_money + $amount_withdraw;

		// work out money in bank
		$bank_money = $player_bank - $amount_withdraw;

		// update money and bank
		$sql = "UPDATE `cf_users` SET `money` = '$new_money', `bank` = '$bank_money' WHERE `id`='" . $player_accountid . "' LIMIT 1";
		$rs = mysql_query($sql) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error());

		}
}
//unset($amount_withdraw);
}



?>


<table align="center" class = "standard">


<tr>
<td colspan="4">
<center><b>Bank</b></center>
</td>
</tr>

<?php if(isset($msg)) { ?>

<tr>
<td colspan="4">
<center><font color="red"><?php echo $msg; ?></font></center>
</td>
</tr>

<?php unset($msg); } ?>

<tr>
<td>Money on Hand</td>  
<td>$<?php if(isset($amount_deposit) || isset($amount_withdraw)) { echo number_format($new_money); } else { echo number_format($player_money); } ?></td>
<td>Money in the Bank</td> 
<td>$<?php if(isset($amount_deposit) || isset($amount_withdraw)) { echo number_format($new_bank); } else { echo number_format($player_bank); } ?></td>
</tr>

<tr>
<td colspan="4"></td>
</tr>

<form name="deposit" action="index.php?page=bank" method="post">
<tr>
<td><b>Deposit</b></td>
<td colspan="2"> <center> <input type="submit" value="Deposit"> </center> </td>
<td> <center> <input type="text" size="15" name="amount_deposit" value="<?php if(isset($amount_deposit) || isset($amount_withdraw)) { echo $new_money; unset($new_money);  } else { echo $player_money; } ?>"> </center> </td>
</tr>
</form>

<form name="withdraw" action="index.php?page=bank" method="post">
<tr>
<td><b>Withdraw</b></td>
<td colspan="2"> <center> <input type="submit" value="Withdraw"> </center> </td>
<td> <center> <input type="text" size="15" name="amount_withdraw" value="<?php if(isset($amount_deposit) || isset($amount_withdraw)) { echo $new_bank; unset($new_bank); } else { echo $player_bank; } ?>"> </center> </td>
</tr>
</form>

</table>

basically, I have 2 separate forms.

 

1 has a text box in it called "amount_deposit"

 

and the other one has a text box called "amount_withdraw"

 

basically, I want them to have the default value of whatever is in $player_money for amount_deposit, and $player_bank for amount_withdraw.

 

now, when they click either one of the submit buttons, it checks whether $_POST['amount_deposit'] is set, or if $_POST['amount_withdraw'] is set.

 

depending on which one "is set" it will run mysql_query's on the database. Which change $player_money and $player_bank.

 

but when someone clicks one of the submit buttons, it posts back to the same page, does the queries, but the new amount for $player_money and $player_bank isn't shown in amount_withdraw or amount_deposit. The person has to refresh the page there self after  pressing submit just to see the new amounts in $player_money and $player_bank. So what I'm trying to do is grab $new_money and $new_bank and echo them into the page if amount_deposit or if amount_withdraw has been set. and then unset them so they can use one of the 2 forms again and see the right amounts for $player_money and $player_bank.

 

I hope that makes it clearer  :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.