PDA

View Full Version : Variable being reset after isset



TheCase
08-22-2008, 10:04 AM
Hi,

This is part of my code


switch ($ladderd) {

case 'eu2':
$ladder = 'aeu2';
break;

case 'eu4':
$ladder = 'aeu4';
break;

case 'eu6':
$ladder = 'aeu6';
break;

case 'eu8':
$ladder = 'aeu8';
break;

default:
$ladder = 'aeu12';
break;

}

But when I do


if(isset($_POST['submit']))

echo "$ladder";

I get an error Notice: Undefined index: $ladder
but it echos out before the isset but not after any ideas?

btw $ladderd is defined by a dropdown selection

Thanks

rangana
08-22-2008, 10:40 AM
I haven't run your code yet, but on the first look, it seems you have typo:


switch ($ladderd) {

TheCase
08-22-2008, 02:26 PM
No. $ladderd is defined by

$ladderd = $_POST['ladder'];

I made it with a d on the end. I can echo out $ladder before the isset and it produces the correct results but just not after the isset it comes out blank so there is no typo or anything as such anywhere.

Thanks

Twey
08-22-2008, 06:10 PM
The error is elsewhere in your code.

That switch, however, can be replaced:
$ladder = in_array($ladderd, array('eu2', 'eu4', 'eu6', 'eu8'))
? 'a' . $ladderd
: 'aeu12';

TheCase
08-22-2008, 09:09 PM
Im still getting

Notice: Undefined variable: ladder
When echoed $ladder after the isset

It works before the isset though

techietim
08-22-2008, 09:34 PM
Normally that wouldn't show. Your PHP configuration is set to display too much information.

Open up your php.ini file and set your error_reporting to:


error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT

TheCase
08-22-2008, 09:43 PM
Ive enabled PHP error reporting because $ladder was echoing blank so I wanted to know what was going on.

Thanks

techietim
08-22-2008, 10:18 PM
Are you giving us ALL the code? Maybe you should paste your entire script.

Nile
08-22-2008, 10:20 PM
No. $ladderd is defined by

$ladderd = $_POST['ladder'];

I made it with a d on the end. I can echo out $ladder before the isset and it produces the correct results but just not after the isset it comes out blank so there is no typo or anything as such anywhere.

Thanks


He is defendantly not giving us all the code.

TheCase
08-22-2008, 10:28 PM
All the code



<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);

require_once('./forum/SSI.php');
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 ////////////////////////////////////////////

if ($eu2 == 0){
$seu2 = '<font color=\'red\'>Not Joined</font>';

}else{
$seu2 = "$ladderstatus2 Points";
}

if ($eu4 == 0){
$seu4 = '<font color=\'red\'>Not Joined</font>';

}else{
$seu4 = "$ladderstatus4 Points";
}

if ($eu6 == 0){
$seu6 = '<font color=\'red\'>Not Joined</font>';

}else{
$seu6 = "$ladderstatus6 Points";
}

if ($eu8 == 0){
$seu8 = '<font color=\'red\'>Not Joined</font>';

}else{
$seu8 = "$ladderstatus8 Points";
}

if ($eu12 == 0){
$seu12 = '<font color=\'red\'>Not Joined</font>';

}else{
$seu12 = "$ladderstatus12 Points";
}

}}}


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

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

$ladderd = $_POST['ladderd'];

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

$p = 'p';

$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');

//$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());

}}
////////////////////////////
///////// Finish is pressed
////////////////////////////
//$teamchallengedropdown = $_POST['cteam'];

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'));

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

$dbid = (mysql_insert_id());

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');
?>

motormichael12
08-23-2008, 02:48 PM
This:


if ($eu2 == 0){
$seu2 = '<font color=\'red\'>Not Joined</font>';

}else{
$seu2 = "$ladderstatus2 Points";
}

if ($eu4 == 0){
$seu4 = '<font color=\'red\'>Not Joined</font>';

}else{
$seu4 = "$ladderstatus4 Points";
}

if ($eu6 == 0){
$seu6 = '<font color=\'red\'>Not Joined</font>';

}else{
$seu6 = "$ladderstatus6 Points";
}

if ($eu8 == 0){
$seu8 = '<font color=\'red\'>Not Joined</font>';

}else{
$seu8 = "$ladderstatus8 Points";
}

if ($eu12 == 0){
$seu12 = '<font color=\'red\'>Not Joined</font>';

}else{
$seu12 = "$ladderstatus12 Points";
}

Could probably be this:



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

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

i$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";

And this:


$p = 'p';

$currentpointsp = "$ladderd$p";

to



$currentpointsp = "{$ladderd}p";

TheCase
08-23-2008, 03:49 PM
Thanks for that optimization but still the $ladder cannot be echoed after the isset but can before. Any ideas?

Thanks