Daney11 Posted February 8, 2008 Share Posted February 8, 2008 Hey guys <tr> <td width="208" height="22" bgcolor="<?php echo $color1 ?>"> Result Team Tag</td> <td width="300" height="22" bgcolor="<?php echo $color1 ?>"><input class="forminput" name="result_teamtag" type="text" value="<?php if (isset($_POST['result_teamtag'])) echo $_POST['result_teamtag']; ?>" /></td> <tr> <td width="208" height="22" bgcolor="<?php echo $color ?>"> Result Game</td> <td width="300" height="22" bgcolor="<?php echo $color ?>"><select class="forminput" name="result_game"><?php $gamequery=mysql_query("SELECT * from `games` WHERE `game_active`='Yes' ORDER BY `game_name` ASC"); while($game=mysql_fetch_array($gamequery)){ echo "<option value=\"".$game['game_image']."\">".stripslashes($game['game_name'])."</option>\n"; } ?> </select> Im using this to submit data.... It all works fine expect when i submit the data and if there is an error the POST values all come up correct but the game value. The values from the drop down disappear. The values are there when the form has not been submitted but afterwards it dissppears. Quote Link to comment Share on other sites More sharing options...
aschk Posted February 8, 2008 Share Posted February 8, 2008 You need to put a "selected" tag into the html option that was selected. This requires extra processing in your loop but i'm sure you can work it out Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 8, 2008 Author Share Posted February 8, 2008 Hmm, im not actually sure on how to work that out if im honest lol. Im just correcting all the bugs on my site. Quote Link to comment Share on other sites More sharing options...
aschk Posted February 8, 2008 Share Posted February 8, 2008 I'll give you an example of the html (because i can't quite be bothered to write out the PHP part) <select name="dropdown"> <option value="1">1</option> <option value="2" selected>2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> As you can see from the above the "selected" option is set, meaning when the dropdown is rendered in the browser of the users choice it will present the "default" option as a being 2. All you have to do now is get PHP to do that for you. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 8, 2008 Share Posted February 8, 2008 Try changing your while loop to this <?php while($game=mysql_fetch_array($gamequery)){ if (isset($_POST['result_game'])){ if ($_POST['result_game'] == $game['game_image']) $select = "selected='selected'"; else $select = ""; } else { $select = ""; } echo "<option value='{$game['game_image']}' $select\>".stripslashes($game['game_name'])."</option>\n"; } ?> Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 8, 2008 Author Share Posted February 8, 2008 pocobueno1388 when posting the result is the same. it dissappears Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 8, 2008 Author Share Posted February 8, 2008 Its something to do with the $_POST but i cannot see why at all. Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 8, 2008 Author Share Posted February 8, 2008 Without submitting the form this peice of code <td width="300" height="22" bgcolor="<?php echo $color ?>"><select class="forminput" name="result_game"><?php $gamequery=mysql_query("SELECT * from `games` WHERE `game_active`='Yes' ORDER BY `game_name` ASC"); while($game=mysql_fetch_array($gamequery)){ if (isset($_POST['result_game'])){ if ($_POST['result_game'] == $game['game_image']) $select = "selected='selected'"; else $select = ""; } else { $select = ""; } echo "<option value='{$game['game_image']}' $select\>".stripslashes($game['game_name'])."</option>\n"; } ?> </select> </td> works perfect. But when the form has been submitted and there is an error, nothing is being display and all the options have been deleted. I really cannot figure this one out. Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 8, 2008 Author Share Posted February 8, 2008 In normal text boxes i have <tr> <td width="208" height="22" bgcolor="<?php echo $color ?>"> Result Link</td> <td width="300" height="22" bgcolor="<?php echo $color ?>"><input class="forminput" name="result_link" type="text" value="<?php if (isset($_POST['result_link'])) echo $_POST['result_link']; ?>" /></td> </tr> and that works perfect, if there is an error the submitted text still stays in the box Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 8, 2008 Share Posted February 8, 2008 Can you post more of your code? Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 8, 2008 Author Share Posted February 8, 2008 What parts of the code would you like to see? The rest is just the submitting stage which works perfectly and other bits are just the text areas with my above post in. Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 8, 2008 Author Share Posted February 8, 2008 Ive managed to do this <select class="forminput" name="result_game"><?php $gamequery=mysql_query("SELECT * from `games` WHERE `game_active`='Yes' ORDER BY `game_name` ASC"); while($game=mysql_fetch_array($gamequery)){ if (isset($_POST['result_game'])){ if ($_POST['result_game'] == $game['game_image']) $select = "selected='selected'"; else $select = ""; } else { $select = ""; } echo "<option value='{$game['game_image']}' $select>".stripslashes($game['game_name'])."</option>\n"; } ?> <option value="<?php if (isset($_POST['result_game'])) echo $_POST['result_game']; ?>"><?php if (isset($_POST['result_game'])) echo $_POST['result_game']; ?></option> </select> Basically when its submitted now and/if returns an error on other things being submitted i get the output of the value Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 8, 2008 Author Share Posted February 8, 2008 Im sure im doing it right though :S Quote Link to comment Share on other sites More sharing options...
Daney11 Posted February 8, 2008 Author Share Posted February 8, 2008 Ive approched this a different way now <?php $gamequery=mysql_query("SELECT * from `games` WHERE `game_active`='Yes' ORDER BY `game_name` ASC"); $row_games = mysql_fetch_array($gamequery); ?> <select class="forminput" name="result_game"> <?php do { ?> <option value="<?php echo $row_games['game_image'] ?>"<?php if (!(strcmp($row_games['game_image'], "$game_name"))) {echo " SELECTED";} ?>><?php echo $row_games['game_name'] ?></option> <?php } while($row_games=mysql_fetch_assoc($gamequery)); $rows = mysql_num_rows($gamequery); if($rows > 0) { mysql_data_seek($gamequery, 0); $row_games = mysql_fetch_assoc($gamequery); } ?> </select> </td> Im getting the same result though... When its been submitted and my errors come up for illegal characters etc... the select box options dissappear. Quote Link to comment Share on other sites More sharing options...
Dane Posted February 9, 2008 Share Posted February 9, 2008 Sorry for all the posting. Im have changed the coding once again to... <?php $gamequery=mysql_query("SELECT * from `games` WHERE `game_active`='Yes' ORDER BY `game_name` ASC"); ?> <select class="forminput" name="result_game"> <?php while($row_games=mysql_fetch_array($gamequery)){ echo "<option value=\"".$row_games['game_image'].""; if ($row_games['game_image'] == $_POST['result_game']) { echo " selected"; } echo "\">".$row_games['game_name']."</option>\""; } ?> </select> <?php echo $_POST['result_game']; ?> Notice the <?php echo $_POST['result_game']; ?> at the bottom. That is there just to see if they value is posting and it is posting. But after the post the <option>s dissappear. Quote Link to comment Share on other sites More sharing options...
Dane Posted February 10, 2008 Share Posted February 10, 2008 Anyone have any clues? Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.