Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Variable being reset after isset

  1. #1
    Join Date
    Aug 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Variable being reset after isset

    Hi,

    This is part of my code

    PHP 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

    PHP Code:
    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

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    I haven't run your code yet, but on the first look, it seems you have typo:
    Code:
    switch ($ladderd) {
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. #3
    Join Date
    Aug 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The error is elsewhere in your code.

    That switch, however, can be replaced:
    Code:
    $ladder = in_array($ladderd, array('eu2', 'eu4', 'eu6', 'eu8'))
        ? 'a' . $ladderd
        : 'aeu12';
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Im still getting

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

    It works before the isset though

  6. #6
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    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:
    Code:
    error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT

  7. #7
    Join Date
    Aug 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ive enabled PHP error reporting because $ladder was echoing blank so I wanted to know what was going on.

    Thanks

  8. #8
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    Are you giving us ALL the code? Maybe you should paste your entire script.

  9. #9
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Quote Originally Posted by TheCase View Post
    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.
    Jeremy | jfein.net

  10. #10
    Join Date
    Aug 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    All the code

    PHP 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 == && $aeu2 == 0){
     echo 
    '
    <option value="eu2">EU 2v2</option>
    '
    ; }
    if(
    $eu4 == && $aeu4 == 0){
     echo 
    '
     <option value="eu4">EU 4v4</option>
     '
    ; }
    if(
    $eu6 == && $aeu6 == 0){
     echo 
    '
     <option value="eu6">EU 6v6</option>
     '
    ; } 
    if(
    $eu8 == && $aeu8 == 0){
     echo 
    '
     <option value="eu8">EU 8v8</option>
     '
    ; } 
    if(
    $eu12 == && $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');
    ?>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •