473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How to insert one item from PHP drop down?

Hey,
I need to insert a an item from my drop down into MySQL. However at the moment i am getting all the values and i need to know if theres a way to submit the values individually.
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $sql="SELECT name, no FROM test";
  3.  echo "<select name=\"name\">";  
  4.  echo "<option size=75>name | no</option>"; 
  5.   if ($result=mysql_query($sql)) {  
  6.   while ($data=mysql_fetch_assoc($result))  
  7.  {  
  8.  echo "<option size=75>$data[name]&nbsp; $data[no]</option>";  
  9.  }  
  10.  } 
  11.  else 
  12.  {
  13.  echo "<!-- SQL Error ".mysql_error()." -->";
  14.  }
  15.  echo "</select>";
  16. ?>
  17.  
So basically i want to insert into test.name the name in the drop down and insert into test.no the no next to the name. It works at the moment but everything goes into the name column echo "<select name=\"name\">"; and no is empty. Any help would be appreciated

Thanks matt.
Jan 11 '11 #1
3 2096
Dormilich
8,658 Expert Mod 8TB
- size is an invalid attribute for <option> (it belongs into <select>)
- array keys must be quoted ($array['key'])

you mean the submitted value doesn’t go in the right database field? then there’s something wrong with your insert query.
Jan 15 '11 #2
Hi dormilich,
Sorry i didnt look at the size att when i typed it. The problem is occuring becuase alot of the data has similiar names. eg id 4242 & id 4342. So i need to SHOW a NAME and an ID in the drop down but ONLY submit the ID to the database. Its all very messy at this stage. They were previously using ms access, absolute nightmare. Thanks for the reply tho. I have taken a different route now and instead i have supplied a drop down with just the id and a simple ajax table that displays the MySQL row details for that id below the drop down.

thanks.
Jan 16 '11 #3
Dormilich
8,658 Expert Mod 8TB
if you only need the ID to pass, put that into the value attribute.
Expand|Select|Wrap|Line Numbers
  1. <option value="id">name</option>
  2. // or
  3. <option value="id">name id</option>
Jan 16 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Rob | last post by:
I have 2 drop down menus. 1 is to pick a Province and the other is to pick a trade (plumbng electrical etc) The user selects which province and then what trade then hits submit which should...
10
by: Ryan McGeary | last post by:
In a <select> drop-down, the onchange event isn't called when scrolling through the dropdown using the mouse-wheel and when crossing over a new <optgroup>. Using the example below, notice how...
1
by: jcombalicer | last post by:
How will you make a drop down list that rely information from another drop down list with the help of row source, sql and query not with the of form, pages and vba. Every department has...
3
by: John Walker | last post by:
Hi, On an ASP.NET page I have a drop down list control. When the user pulls down the list and makes a selection, I perform validation, and if the validation fails I want the selected item in...
3
by: Michael Meckelein | last post by:
Hello, I run into trouble move down a selected item in a listbox. The code moving down the item is the following one: for (int j = lv.SelectedItems.Count-1; j >=0; j--) { ListViewItem...
1
by: Grimason-NZ | last post by:
Hi, I have MS Office Pro 97 and have built a database that has two tables. The MS Office Pro 97 manual does not appear to cover how to make a Drop down list and thus I need some advice on the how...
0
by: Afton Wynona | last post by:
I have an insert Item template, I want to use it as the edit item template as well. And I want to use it in other pages. Can I store this template somewhere in a control or something, so I can...
3
by: scott | last post by:
Hello all, I am ripping my hair out over this and maybe someone could help. I have a site that has groups and subgroups of those groups that all have int id's. I am trying to have a...
4
by: nathanh | last post by:
Hey all, I am looking for help on creating a after update to filter another drop down box. I am looking to have a drop down box based on a table and from this drop down box filter another drop down...
2
by: billybob206 | last post by:
Howdy, Is there a way to make the Insert Item Templete in the FormView in VS ASP.Net the default view of a webpage. (The purpose is I'm trying to create a new user page without having to search...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.