ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The users selects the position they want from the array populated by the following:
PHP Code:
$query = "SELECT posID, position FROM position ORDER BY posID"; $result = mysql_query($query); while($pos = mysql_fetch_array($result)) { print("<option value=\"$pos[0]\">$pos[1]\n"); } print("</select>
My problem is that when this is submitted to the mySQL database then the value "Array" is entered into the database rather the option selected from the drop down? Am I doing something blatantly wrong or is this never going to work this way?
Your program looks correct. I added a table to my db, added some data, and ran your exact program. My results were correct. It has to be the way you are grabbing the data from the form and inserting. it.
Code:
use test;
DROP TABLE IF EXISTS position;
create table position
(
posID varchar(35),
position int(5)
);
mysql> insert into position values ( 'five', 5 );
mysql> insert into position values ( 'ten', 10 );
mysql> insert into position values ( 'one', 1 );
PHP Code:
<?php mysql_connect( "localhost", "test", "test" ) or die ("Unable to connect"); mysql_select_db( "test" ) or die( "Unable to select database test" );
$query = "SELECT posID, position FROM position ORDER BY posID"; $result = mysql_query($query); while($pos = mysql_fetch_array($result)) { print("<option value=\"$pos[0]\">$pos[1]\n"); } print("</select>\n");
Sorry must have not made myself clear about what the porblem was, the drop down displays fine, the problem is when the form data is posted to my script which for this code adds a player to a database. In the column 'position' the value Array is entered rather than the actual position selected from the drop down.
PHP Code:
$query = "INSERT INTO members (student_no, first_name, last_name, email_address, mobile, ncl_phone, other_phone, position) VALUES ('$student_no', '$first_name', '$last_name', '$email', '$mobile', '$ncl', '$other', '$pos')"; $result = mysql_query($query) or die ("Couldn't add player to members table. Check the information and try again.");
The value pos should, I assume, contain the actual data from the array. Although this is not actually happening!
Any further ideas?
Cheers
Mounters
Got it sorted, I had put the worng variable to be added to the database, so many similar ones, I was calling the variable for the actual select values rather than the one for the select statement itself.
Cheers for the help anyhow.
Mounters
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.