Jump to content

POST


Daney11

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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";
   
}

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.