Page 1 of 1

dynamic dropdown list not passing selection

Posted: Thu Dec 06, 2007 12:45 pm
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:

Posted: Thu Dec 06, 2007 1:13 pm
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).

I GOT IT!

Posted: Thu Dec 06, 2007 7:02 pm
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:

Take a look at this example it might help

Posted: Thu Dec 06, 2007 7:28 pm
by yacahuma

Posted: Thu Dec 06, 2007 7:40 pm
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)