Darkmatter5 Posted June 6, 2008 Share Posted June 6, 2008 I have this dropdown list: <tr> <td class="style25">State:</td> <td> <?php include 'library/dbconfig.php'; include 'library/opendb.php'; $query="SELECT state_id, state, state_abbrev FROM byrnjobdb.states ORDER BY state ASC"; $result=mysql_query($query); echo "<select id='state' method='get' tabindex='5'>"; echo "<option>---Select---</option>"; while ($row=mysql_fetch_array($result)) { $r1=$row['state_id']; $r2=$row['state']. ", " .$row['state_abbrev']; echo "<option value='$r1'>$r2</option>"; } echo "</select>"; include 'library/closedb.php'; ?> </td> <td class="style5"><div align="center"><input name='cl_state' type='checkbox' value='1' /></div></td> </tr> And I have this submit button code: <tr> <td colspan="3"><div align="center"> <div align="right" class="style3">Function Status =></div> </div></td> <td colspan="2" class="style23"> <?php if(isset($_POST['editemployee'])) { include 'library/dbconfig.php'; include 'library/opendb.php'; $result=mysql_query("SELECT first_name,last_name FROM byrnjobdb.employees WHERE employee_id=" .$_POST['employee']); $row=mysql_fetch_array($result); //handling textboxes foreach (array('first_name','last_name','address','city','zip_code','home_phone','cell_phone') as $field) { if ($_POST[$field]) { $data[]=$field. "=" ."'{$_POST[$field]}'"; } } //handling checkboxes if ($_POST['active_employee']==1) { $data[]="active_employee='Yes'"; } else $data[]="active_employee='No'"; if ($_POST['lic_rpls']==1) { $data[]="lic_rpls='Yes'"; } else $data[]="lic_rpls='No'"; if ($_POST['lic_pe']==1) { $data[]="lic_pe='Yes'"; } else $data[]="lic_pe='No'"; //handling dropdown lists if ($_POST['state']!=NULL) { $data[]="state_id=" ."'{$_POST['state_id']}'"; } foreach ($data as $value) { $updatedata="UPDATE byrnjobdb.employees SET $value WHERE employee_id=" .$_POST['employee']; echo $updatedata. "<br>"; // mysql_query($updatedata) or die(mysql_error() . ": $updatedata"); } echo $row[first_name]. " " .$row[last_name]. " UPDATED in employees table..."; include 'library/closedb.php'; } ?> </td> </tr> As you can see I've commented out the actual submission of data to the database and put in an echo of the variables created to be passed to the commented out mysql_query function, so I can see what is actually be passed to mysql_query. Upon doing this and running the page and attempting to update state from the dropdown list, I only get the following output: UPDATE byrnjobdb.employees SET active_employee='Yes' WHERE employee_id=1 UPDATE byrnjobdb.employees SET lic_rpls='No' WHERE employee_id=1 UPDATE byrnjobdb.employees SET lic_pe='No' WHERE employee_id=1 FIRSTNAME LASTNAME UPDATED in employees table... Assuming Texas has a state_id of 1, can anyone see why the following line is NOT included with the list of constructed variables? UPDATE byrnjobdb.employees SET state_id=1 WHERE employee_id=1 Thanks! Link to comment https://forums.phpfreaks.com/topic/108994-help-with-pulling-dropdown-list-value-into-variable/ Share on other sites More sharing options...
tapos Posted June 6, 2008 Share Posted June 6, 2008 echo "<select id='state' method='get' tabindex='5'>"; U didn't give any name of the drop down list. use bellow instead of above echo "<select id='state' name="state" tabindex='5'>"; BTW what is the meaning of using a method attribute in select tag (method attribute is only for form tag). Link to comment https://forums.phpfreaks.com/topic/108994-help-with-pulling-dropdown-list-value-into-variable/#findComment-559151 Share on other sites More sharing options...
tapos Posted June 6, 2008 Share Posted June 6, 2008 echo "<select id='state' method='get' tabindex='5'>"; U didn't give any name of the drop down list. use bellow instead of above echo "<select id='state' name="state" tabindex='5'>"; BTW what is the meaning of using a method attribute in select tag (method attribute is only for form tag). Link to comment https://forums.phpfreaks.com/topic/108994-help-with-pulling-dropdown-list-value-into-variable/#findComment-559155 Share on other sites More sharing options...
Darkmatter5 Posted June 6, 2008 Author Share Posted June 6, 2008 So not including the method attribute won't affect the dropdown list at all? I'll delete it if that's what you're telling me. I thought it was the only way the let PHP pull it's value into a variable. Okay I just tried it and it worked! Thanks! Link to comment https://forums.phpfreaks.com/topic/108994-help-with-pulling-dropdown-list-value-into-variable/#findComment-559159 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.