Help With Undefined Variable

Having trouble finding the right solution for errors in php. The error reads…

Notice: Undefined variable: selected in C:\wamp\www\tcpro_34000\register.php on line 264

Call Stack

Time Memory Function Location

1 0.0124 200688 {main}( ) …\register.php:0

Line 264 then reads…

echo “<option class=“option” value=”".$row[‘groupname’].""".$selected.">".$row[‘groupname’]."\n\r";
$selected="";

Any idea why this is happening? Any help would be nice thanks.

Can you use the php code button to wrap the code in please.

The variable does not have anything assigned to it.

[php]$selected
[/php]

52 if ( isset($_POST[‘btn_submit’]) AND in_array($_POST[‘lst_group’],$G->getGroups()) )
53 {
54 if (!strlen($_POST[‘txt_lastname’]) || !strlen($_POST[‘txt_username’]) || !strlen($_POST[‘txt_email’]) ||
&

<?php $groups = $G->getAll(); foreach ($groups as $row) { if ( isset($_POST['lst_group']) && strlen($_POST['lst_group']) && ($row['groupname']==$_POST['lst_group']) ) $selected=" SELECTED"; echo "".$row['groupname']."\n\r"; $selected=""; } ?>

I cant help witout you using the correct button where you type above press the button that says PHP then put your code in between the php tages like below.
Read the the big [size=14pt]important[/size] message when your typing.

[PHP.] code goes here [/php.]

Sorry, my bad…

if ( isset($_POST['btn_submit']) AND in_array($_POST['lst_group'],$G->getGroups()) ) { if (!strlen($_POST['txt_lastname']) || !strlen($_POST['txt_username']) || !strlen($_POST['txt_email']) ||

[php] <?php
$groups = $G->getAll();
foreach ($groups as $row) {
if ( isset($_POST[‘lst_group’]) && strlen($_POST[‘lst_group’]) && ($row[‘groupname’]==$_POST[‘lst_group’]) ) $selected=" SELECTED";
echo “<option class=“option” value=”".$row[‘groupname’].""".$selected.">".$row[‘groupname’]."\n\r";
$selected="";
}
?>[/php]

Strange because it is assigned SELECTED.

[php]
$selected=“SELECTED”;
echo “<option class=“option” value=”".$row[‘groupname’].""".$selected.">".$row[‘groupname’]."\n\r";
$selected="";
}
[/php]

should it have select= in the code ?

[php]
$selected=“SELECTED”;
echo “<option class=“option” value=”".$row[‘groupname’]."" selected=".$selected.">".$row[‘groupname’]."\n\r";
$selected="";
}
[/php]

The line above it though is saying if is set so one of these are not working so the selected is not being assigned.

[php]if ( isset($_POST[‘lst_group’]) && strlen($_POST[‘lst_group’]) && ($row[‘groupname’]==$_POST[‘lst_group’]) ) $selected=" SELECTED";[/php]

Try to echo out the POST vars

[php]if (! isset($_POST[‘lst_group’]) || ($row[‘groupname’]!=$_POST[‘lst_group’])
echo ‘lst_group = ‘.$_POST[‘lst_group’].’
’;
echo ‘str len = ‘.strlen($_POST[‘lst_group’].’
’;
echo ‘row group = ‘.$row[‘groupname’].’
’;
}

if ( isset($_POST[‘lst_group’]) && strlen($_POST[‘lst_group’]) && ($row[‘groupname’]==$_POST[‘lst_group’]) ) $selected=" SELECTED";
[/php]

Yes thank you also here is another example I came across dealing with the same sort of errors, here it goes…

( ! ) Notice: Undefined variable: score_game_filter in C:\wamp\www\standings\standings_functions.php on line 74
Call Stack

Time Memory Function Location

1 0.0036 232384 {main}( ) …\standings.php:0
2 0.0190 254960 sls_team_schedule( ) …\standings.php:139

( ! ) Notice: Undefined variable: score_sort in C:\wamp\www\standings\standings_functions.php on line 74
Call Stack

Time Memory Function Location

1 0.0036 232384 {main}( ) …\standings.php:0
2 0.0190 254960 sls_team_schedule( ) …\standings.php:139

[php]<?php

$queryscores=“SELECT sportsdb_wins.winid, sportsdb_wins.windate, sportsdb_wins.wintime,
sportsdb_wins.rf, sportsdb_wins.ra, sportsdb_wins.wincomments,
sportsdb_wins.field, sportsdb_wins.winortie,
sportsdb_teams2.teamname AS winningteam,
sportsdb_teams.teamname AS losingteam
FROM sportsdb_wins, sportsdb_teams AS sportsdb_teams2, sportsdb_teams
WHERE sportsdb_teams2.teamid = sportsdb_wins.winner
AND sportsdb_teams.teamid = sportsdb_wins.loser
$team_specific_sort
73. $score_game_filter
74. ORDER BY wintime $score_sort”;
75.
$resultscores=mysql_query($queryscores);

while ($scores = mysql_fetch_array($resultscores, MYSQL_ASSOC)) {

$windateheader=$scores['windate'];
$windateformatted=date("F d, Y",$windateheader);
$wintime=$scores['wintime'];
$hour=date('g',$wintime);
$minute=date('i',$wintime);
$ampm=date('a',$wintime);

?>[/php]

The code you have there means nothing to the error.

The code has to be some other place that assigns the $score_game_filter var a value.

Under further consideration it seems to me that the PHP version 5.4.3 on this Wamp server has been less then ideal. I have not ran into many problems in the past should I go back to a older PHP version? Most of the coding I’m dealing with is from a few years ago. Please let me know if using a PHP version from years back would help with some of these problems and which PHP version might be best for older coding, thanks.

No point going backwards as you will have to change it sooner than later,

I would think most servers are php5 now

I think it has to do more with the server I downloaded and that it is not set up right. I will try downloading vcredist_x86.exe from Microsoft. Then try downloading WAMPSERVER (32 BITS & PHP 5.3) 2.2E
Apache 2.2.22 – Mysql 5.5.24 – PHP 5.3.13 XDebug 2.1.2 XDC 1.5 PhpMyadmin 3.4.10.1 SQLBuddy 1.3.3 webGrind 1.0 and hope that will solve some of these issues. I’ll give it a try and see how it goes, I’ll let you know if anything changes.

I uploaded it online using and FTP Client, it finally started to work. Must be something I did wrong or did not do when downloading Wamp. I think I’ll try using a different server. Thanks for all the help. Not completely sure why it’s not working correctly. I did find a way around it, if you have any idea why this is the case or need more details to why it’s mixed up please let me know other than that I’m fine where I at for now.

Sponsor our Newsletter | Privacy Policy | Terms of Service