dynamic dropdown list not passing selection

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MaxBodine
Forum Newbie
Posts: 2
Joined: Wed Dec 05, 2007 3:41 pm

dynamic dropdown list not passing selection

Post by MaxBodine »

I have a dynamic dropdown list that passes the first item in the list, not the selected. I have tried so many things. I would greatly appreciate help. I have posted on serveral forums. here it the code:

Code: Select all

<? mysql_select_db($database_connJDD, $connJDD);
$query_rsSKU = "SELECT products.SKU FROM products";
$rsSKU = mysql_query($query_rsSKU, $connJDD) or die(mysql_error());
$row_rsSKU = mysql_fetch_assoc($rsSKU);
$totalRows_rsSKU = mysql_num_rows($rsSKU);
?> 
<table align="center">
 <tr>
 <td>
 
 <p align="center">Select SKU for <br />
      Product Update  </p>	
		<form id="form5" name="form5" method="post" action="updateProducts.php?ProductNo=<?php echo $row_rsSKU['SKU']; ?>">				
        <select name="skuList">
          <?php
do {  
?>
          <option value="<?php echo $row_rsSKU['SKU']?>"<?php if (!(strcmp($row_rsSKU['SKU'], $row_rsSKU['SKU']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsSKU['SKU']?></option>
          <?php
} while ($row_rsSKU = mysql_fetch_assoc($rsSKU));
  $rows = mysql_num_rows($rsSKU);
  if($rows > 0) {
      mysql_data_seek($rsSKU, 0);
	  $row_rsSKU = mysql_fetch_assoc($rsSKU);
  }
?>
        </select> <br />
		<input name="Update" type="submit" value="Update Product" />  
		</form>
    </td>
  </tr>
</table>  
 <?php
mysql_free_result($rsSKU);
?>
I have tried passing $_POST['skuList'] everything I can think of and it still passes the first item. Again I thanking you in advance for help! I have been working on this for a LONG time and just can't see my error. :cry:
SBukoski
Forum Contributor
Posts: 128
Joined: Wed May 21, 2003 10:39 pm
Location: Worcester, MA

Post by SBukoski »

What exactly are you trying to do here?

Is there a reason you are passing 'ProductNo' as part of the action? In your example, ProductNo will be the first record returned every single time.

And this bit of code:

Code: Select all

strcmp($row_rsSKU['SKU'], $row_rsSKU['SKU'])


will always return 0 as you are comparing the same two strings. So, working with what you provided, $_GET['ProductNo'] will always return the SKU for the first record returned in the query. And $_POST['skuList'] will return whatever was selected in the pelldown. But the default selection will always be the first option (i.e., the first record).
MaxBodine
Forum Newbie
Posts: 2
Joined: Wed Dec 05, 2007 3:41 pm

I GOT IT!

Post by MaxBodine »

Thank you so much! That bit of code was put in by Dreamweaver. I was thinking I had to put the value in a variabe to pass it. But I figured it out from what you explained. Again thanks so much. I was thinking off in left field. I need to keep it simple :oops:
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Take a look at this example it might help

Post by yacahuma »

User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Adding "PLEASE HELPPP" in your title is very poor netiquette. The good people of this community shall help you at their own leisure, so just have a little patience.

I've modified your title for you this time, but in the future try to keep your titles as descriptive as possible.

No harm.. no foul.. carry on... 8)
Post Reply