473,396 Members | 1,872 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,396 software developers and data experts.

Problem With Php Insertion From List! Urgent

8
The following code takes the values from the db and echos them inside a list. Then when the user selects a value from the list, the value must be stored to the db, but this doesn't work. Could anyone help?

Thank you in advance for your effort.

<?php
$query = "SELECT categorydescription, categoryname FROM categories ORDER BY categoryname ASC";
$result = mysql_query($query,$conn) or die('Query failed: ' . mysql_error());
?>
<select name="categoryname" id="categoryname">
<?php
while ($line = mysql_fetch_array($result, MYSQL_NUM)) {
echo "<option value= \"$line[0]\"> $line[1] </option>" ;

}
mysql_free_result($result);



$query ="INSERT INTO orderdetails (CategoryName)
VALUES('$line[0]\')"; mysql_query($query) or die(mysql_error());
?>
Dec 1 '06 #1
2 1020
Hi ...

How do you expect it know ...what the user selected ...
Capture the selected value using form "post" method then insert it into the database.

Try it !
Dec 1 '06 #2
The following code takes the values from the db and echos them inside a list. Then when the user selects a value from the list, the value must be stored to the db, but this doesn't work. Could anyone help?

Thank you in advance for your effort.

<?php
$query = "SELECT categorydescription, categoryname FROM categories ORDER BY categoryname ASC";
$result = mysql_query($query,$conn) or die('Query failed: ' . mysql_error());
?>
<select name="categoryname" id="categoryname">
<?php
while ($line = mysql_fetch_array($result, MYSQL_NUM)) {
echo "<option value= \"$line[0]\"> $line[1] </option>" ;

}
mysql_free_result($result);



$query ="INSERT INTO orderdetails (CategoryName)
VALUES('$line[0]\')"; mysql_query($query) or die(mysql_error());
?>
TKB,

You need to reference the posted selection. Thus, here is your fixed code:
[PHP]$query ="INSERT INTO orderdetails (CategoryName)
VALUES('$_POST[categoryname]')";
mysql_query($query) or die(mysql_error());[/PHP]
Hope that helps.

Sean
Dec 1 '06 #3

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

Similar topics

5
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
0
by: gabe_pu | last post by:
List Box Multiple Selections I have a list box on my page and I´m trying to add new items on it. The insert operation must be under the selected item. When I make the insertion it is done ...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
3
by: Franco Perilli | last post by:
I've compiled this code and no problems, but when I run the program, it prints only the last entry i've inserted. Looks like a problem in the sorted insertion algorithm. Can u help me plz? ...
4
by: Gaijinco | last post by:
I'm doing a template class to make an ordered list. I created a class Person to make an agenda. When I create a new person, there's no problem but when I try to add it to the list it throws a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.