Jump to content

Carry variable over after if


thecase

Recommended Posts

Hi,

 

This is my code

 

<?php

require_once('./forum/SSI.php');

if ($context['user']['is_guest'])
{
   echo 'You need to be logged in.';
   exit();
}
else
{


require_once('./mysql_connect.php');
$username = $context['user']['name'];

$userteamcheck = "SELECT * FROM smf_members WHERE memberName='$username'" or trigger_error("Query: $userteamcheck\n<br />MySQL Error: ". mysql_error());
$userteamcheck2 = mysql_query ($userteamcheck);
while ($userteamcheck3 = mysql_fetch_assoc($userteamcheck2)) {
$teamnamme = $userteamcheck3['team']; 

$ownercheck = "SELECT * FROM aacl_team WHERE teamname='$teamnamme'" or trigger_error("Query: $ownercheck\n<br />MySQL Error: ". mysql_error());
$ownercheck2 = mysql_query ($ownercheck);
while ($ownercheck3 = mysql_fetch_assoc($ownercheck2)) {
$ownerofteam = $ownercheck3['owner']; 
$eu2 = $ownercheck3['eu2']; 
$eu4 = $ownercheck3['eu4']; 
$eu6 = $ownercheck3['eu6']; 
$eu8 = $ownercheck3['eu8']; 
$eu12 = $ownercheck3['eu12']; 

$aeu2 = $ownercheck3['aeu2']; 
$aeu4 = $ownercheck3['aeu4']; 
$aeu6 = $ownercheck3['aeu6']; 
$aeu8 = $ownercheck3['aeu8']; 
$aeu12 = $ownercheck3['aeu12']; 

$ladderstatus2 = $ownercheck3['eu2p']; 
$ladderstatus4 = $ownercheck3['eu4p']; 
$ladderstatus6 = $ownercheck3['eu6p']; 
$ladderstatus8 = $ownercheck3['eu8p']; 
$ladderstatus12 = $ownercheck3['eu12p']; 

$id = $ownercheck3['id']; 

if ($ownerofteam != $username){

echo 'You are not leader/captain of this team. <BR><BR><FORM><INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;"> </FORM><BR><BR>
';
require_once('includes/footer.html');
exit();

}else{

/////////////////////////////////// Team Mangament ////////////////////////////////////////////

$seu2 = ($eu2 == 0) ? '<font color=\'red\'>Not Joined</font>' : "$ladderstatus2 Points"; 

$seu4 = ($eu4 == 0) ? '<font color=\'red\'>Not Joined</font>' : "$ladderstatus4 Points"; 

$seu6 = ($eu6 == 0) ? '<font color=\'red\'>Not Joined</font>' : "$ladderstatus6 Points";

$seu8 = ($eu8 == 0) ? '<font color=\'red\'>Not Joined</font>' : "$ladderstatus8 Points";

$seu12 = ($eu12 == 0) ? '<font color=\'red\'>Not Joined</font>' : "$ladderstatus12 Points";

}}}

    
/////////////////////////////////////////////////////// Challenge //////////////////////////////

if(isset($_POST['challengebutton2'])){

$ladderd = $_POST['ladderd'];

$ladder = in_array($ladderd, array('eu2', 'eu4', 'eu6', 'eu8'))
    ? 'a' . $ladderd
    : 'aeu12';

if (isset ($ladder))

$currentpointsp = "{$ladderd}p";

$fetchpoints = "SELECT * FROM aacl_team WHERE teamname='$teamnamme'" or trigger_error("Query: $fetchpoints\n<br />MySQL Error: ". mysql_error());
$fetchpoints2 = mysql_query ($fetchpoints);
while ($fetchpoints3 = mysql_fetch_assoc($fetchpoints2)) {
$currentpoints = $fetchpoints3["$currentpointsp"]; 

echo "
<form action=\"manage_team.php\" method=\"post\">
<table align='center' border='2' bordercolor='005DB3'>
<tr>
<td background='Untitled.gif'><center>Select a team</center></td>
</tr>
<tr>
<td bgcolor=\"FFFFFF\">Team:
<select name=\"cteam\">";

$fetchmorepoints = "SELECT * FROM aacl_team WHERE $ladder='0' AND $currentpointsp <= $currentpoints AND teamname != '$teamnamme'" or trigger_error("Query: $fetchmorepoints\n<br />MySQL Error: ". mysql_error());
$fetchmorepoints2 = mysql_query ($fetchmorepoints);
    while ($fetchmorepoints3 = mysql_fetch_assoc($fetchmorepoints2)) {
    $morepointteam = $fetchmorepoints3['teamname'];
    $morepointteamid = $fetchmorepoints3['id'];

    echo "<option value='" . $morepointteamid . "'>" . $morepointteam . "</option>";

    }
$fetchlesspoints = "SELECT * FROM aacl_team WHERE $ladder='0' AND $currentpointsp >= $currentpoints AND teamname != '$teamnamme'" or trigger_error("Query: $fetchlesspoints\n<br />MySQL Error: ". mysql_error());
$fetchlesspoints2 = mysql_query ($fetchlesspoints);
    while ($fetchlesspoints3 = mysql_fetch_assoc($fetchlesspoints2)) {
    $lesspointteam = $fetchlesspoints3['teamname'];
    $lesspointteamid = $fetchlesspoints3['id'];

    echo "<option value='" . $lesspointteamid . "'>" . $lesspointteam . "</option>";

    }

echo"	</select>
	<div align=\"center\"><input type=\"submit\" name=\"finishchallenge\" value=\"Finish\" /> </div>
<input type=\"hidden\" name=\"finishchallenge2\" valuev=\"TRUE\" />
</td>
</tr>
</table>
</form>
";

require_once('includes/footer.html');

}}

///////// Finish is pressed
////////////////////////////

if(isset($_POST['finishchallenge2'])){

srand((double)microtime()*1000000); 
$arry_txt=preg_split("/--NEXT--/",join('',file("maps.txt"))); 
$randommap = $arry_txt[rand(0,sizeof($arry_txt)-1)];

srand((double)microtime()*1000000); 
$arry_txt=preg_split("/--NEXT--/",join('',file("times.txt"))); 
$randomtime = $arry_txt[rand(0,sizeof($arry_txt)-1)];

$randomdate = date('l j F Y', strtotime('+' . rand(4,10) . ' days')); 

$teamchallengedropdown = $_POST['cteam'];

$query1 = "INSERT INTO aacl_match (`team`, `ladder`, `time`, `date`, `map`, `teamchallenged`) VALUES ('$teamnamme', '$ladder', '$randomtime', '$randomdate', '$randommap', '$teamchallengedropdown')";		
	$result1 = mysql_query ($query1) or trigger_error("Query: $query1\n<br />MySQL Error: " . mysql_error());

$dbid = (mysql_insert_id());



//$query2 = "INSERT INTO aacl_comms (teamname, username, text, datetime) VALUES ($teamnamme, $username, $randomtime, $randomdate)";		
//		$result2 = mysql_query ($query2) or trigger_error("Query: $query1\n<br />MySQL Error: " . mysql_error());

echo "
Completed
<BR><BR><FORM><INPUT TYPE=\"button\" VALUE=\"Back\" onClick=\"history.go(-2);return true\"> </FORM>
";
require_once('includes/footer.html');
exit();

}}
?>

<table align="left" border="2" bordercolor="005DB3">
<tr>
<td background="Untitled.gif"><center>EU ladder managment</center></td>
</tr>
<tr>
<td bgcolor="FFFFFF">
<b>EU 2v2:</b> <?php if($eu2 == 0){ echo"<a href='jeu2.php?id=$id'>Join Ladder</a>"; } else { echo"<a href='qeu2.php?id=$id'>Quit Ladder</a>"; }?><BR>
<b>EU 4v4:</b> <?php if($eu4 == 0){ echo"<a href='jeu4.php?id=$id'>Join Ladder</a>"; } else { echo"<a href='qeu4.php?id=$id'>Quit Ladder</a>";}?><BR>
<b>EU 6v6:</b> <?php if($eu6 == 0){ echo"<a href='jeu6.php?id=$id'>Join Ladder</a>"; } else { echo"<a href='qeu6.php?id=$id'>Quit Ladder</a>"; }?><BR>
<b>EU 8v8:</b> <?php if($eu8 == 0){ echo"<a href='jeu8.php?id=$id'>Join Ladder</a>"; } else { echo"<a href='qeu8.php?id=$id'>Quit Ladder</a>"; }?><BR>
<b>EU 12v12:</b> <?php if($eu12 == 0){ echo"<a href='jeu12.php?id=$id'>Join Ladder</a>"; } else { echo"<a href='qeu12.php?id=$id'>Quit Ladder</a>"; }?>
<BR>
</td>
</tr>


<table align="right" border="2" bordercolor="005DB3">
<tr>
<td background="Untitled.gif"><center>Your team ladder status</center></td>
</tr>
<tr>
<td bgcolor="FFFFFF"><b>EU 2v2:</b> <?php echo "$seu2"; ?>
<BR>
<b>EU 4v4:</b> <?php echo "$seu4"; ?>
<BR>
<b>EU 6v6:</b> <?php echo "$seu6"; ?>
<BR>
<b>EU 8v8:</b> <?php echo "$seu8"; ?>
<BR>
<b>EU 12v12:</b> <?php echo "$seu12"; ?>
</td>
</tr>
</table>

<form action="manage_team.php" method="post">
<table align="center" border="2" bordercolor="005DB3">
<tr>
<td background="untitled.gif"><center>Challenge Team</center></td>
</tr>
<tr>
<td bgcolor="FFFFFF">Ladder: <select name="ladderd">
<?php if($eu2 == 1 && $aeu2 == 0){
echo '
<option value="eu2">EU 2v2</option>
'; }
if($eu4 == 1 && $aeu4 == 0){
echo '
<option value="eu4">EU 4v4</option>
'; }
if($eu6 == 1 && $aeu6 == 0){
echo '
<option value="eu6">EU 6v6</option>
'; } 
if($eu8 == 1 && $aeu8 == 0){
echo '
<option value="eu8">EU 8v8</option>
'; } 
if($eu12 == 1 && $aeu12 == 0){
echo '
<option value="eu12">EU 12v12</option>
'; }
?>
</select> 
<BR> <div align="center"><input type="submit" name="challengebutton" value="Next" /> </div>
<input type="hidden" name="challengebutton2" value="TRUE" />
</td>
</tr>
</table>
</form>

<BR><BR><BR><BR><BR><BR><BR>
<?php
require_once('includes/footer.html');
?>

 

The problem is when I check the query1 ($query1) to see if it all worked the ladder is blank so $ladder is not working bellow the

 

if(isset($_POST['finishchallenge2'])){ 

 

But if I echo $ladder above it works fine. Any ideas?

Thanks

Link to comment
Share on other sites

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.