Jump to content

Dropdown values are empty?


Wayniac

Recommended Posts

Try [ php ] tags.

 

If you want the value to show what is currently in the database, you need to find which one it is and add selected=selected.

 

So:

 

$options = array("Alabama","Alaska","Arizona");
foreach($options As $country){
   echo("<option name='country' value='".$country."'");
   if($country == $row['country']){
      echo(" selected=selected")
   }
   echo(">".$country."</option>\n");
}

$row would be the row returned from the database.

 

-cb-

the code i provided would create the country select box entirely. (Youmay need to modify it slightly to uit your mysql table structure).

 

You can either use it as a template to copy it for each select dropdown, or you can tie it into a function, to save repeating code unnecessarily.

 

-cb-

I placed it within php tags but all I get is a print out of "United States", "Canada", and "United Kingdom"... Their not in any selection box...

 

$options = array("United States","Canada","United Kingdom");
			foreach($options As $bill_country){
			   echo("<option name=\"bill_country\" value=\"\".$bill_country.\"\"");
			   if($bill_country == $row["bill_country"]){
				  echo(" selected=selected");
			   }
			   echo(">".$bill_country."</option>\n");
			}

Hmmmm.... The array is working quite well now, but I can't seem to change the values. If I wish to edit a country and change it from United States to Canada, once I submit and go check, nothing has changed... Something is not getting accepted...

 

<select name="bill_country" class="textBox_center" id="bill_country" style="min-width:200px;" value="<?php $options = array("United States","Canada","United Kingdom");
			foreach($options As $bill_country){
			   echo("<option name=\"bill_country\" value=\"\".$bill_country.\"\"");
			   if($bill_country == $row["bill_country"]){
				  echo(" selected=selected");
			   }
			   echo(">".$bill_country."</option>\n");
			} ?>"/>

Huh... That would explain a lot of my problems... Nothing at all is able to be edited... It seems nothing is will change so therefore is not being send from the database from the main_edit_admin.php. I compared it to my previous pages which work fine, it must be a syntax error... Could someone take a peek and see if they see any discrepencies? A second set of eyes could go a long ways since mine seems to read in a trance after the 6th pass...  :confused:

You dont put value properties inside a select tag.

 

$result = mysql_query("UPDATE spreadsheet SET date='$date', invoice_num='$invoice_num',conf_num='$conf_num , fname='$fname', bill_add='$bill_add', bill_city='$bill_city', bill_zip='$bill_zip' bill_state='$bill_state' bill_country='$bill_country' ship_add='$ship_add' ship_city='$ship_city' ship_zip='$ship_zip' ship_state='$ship_state' ship_country='$ship_country' terms='$terms' item_num='$item_num' description='$description' quantity='$quantity' price='$price' amount='$amount' sh='$sh' total='$total' ccard='$ccard' color='$color' label='$label' email='$email' phone='$phone' order_date='$order_date' inv_total='$inv_total' inv_minus_sales='$inv_minus_sales' trees_sold='$trees_sold' trees_gifted='$trees_gifted' trees_comp='$trees_comp' unit_cost='$unit_cost' sub_total='$sub_total' tax='$tax' total_paid='$total_paid' payment_method='$payment_method' notes='$notes' date_sent='$date_sent' attn='$attn' seedlings='$seedlings' four_four='$four_four' hear_about='$hear_about' order_emp='$order_emp' comm_fname='$comm_fname' comm_lname='$comm_lname' comm_total='$comm_total' comm_date_paid='$comm_date_paid' WHERE spreadsheetid='$spreadsheetid' ",$connect);

 

put your query into a variable:

$query = "UPDATE spreadsheet SET date='$date', invoice_num='$invoice_num',conf_num='$conf_num , fname='$fname', bill_add='$bill_add', bill_city='$bill_city', bill_zip='$bill_zip' bill_state='$bill_state' bill_country='$bill_country' ship_add='$ship_add' ship_city='$ship_city' ship_zip='$ship_zip' ship_state='$ship_state' ship_country='$ship_country' terms='$terms' item_num='$item_num' description='$description' quantity='$quantity' price='$price' amount='$amount' sh='$sh' total='$total' ccard='$ccard' color='$color' label='$label' email='$email' phone='$phone' order_date='$order_date' inv_total='$inv_total' inv_minus_sales='$inv_minus_sales' trees_sold='$trees_sold' trees_gifted='$trees_gifted' trees_comp='$trees_comp' unit_cost='$unit_cost' sub_total='$sub_total' tax='$tax' total_paid='$total_paid' payment_method='$payment_method' notes='$notes' date_sent='$date_sent' attn='$attn' seedlings='$seedlings' four_four='$four_four' hear_about='$hear_about' order_emp='$order_emp' comm_fname='$comm_fname' comm_lname='$comm_lname' comm_total='$comm_total' comm_date_paid='$comm_date_paid' WHERE spreadsheetid='$spreadsheetid' ";

 

Then you would query with the variable, and echo the query if there is an error:

$result = mysql_query($query) or die($query."<br>".mysql_error());

 

Also add a print_r($_POST); to the top just to make sure its submitting the data.

 

-cb-

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.