LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-16-2002, 04:32 PM   #1
mounters
LQ Newbie
 
Registered: Feb 2002
Location: England
Distribution: SuSE 7.3 prof
Posts: 9

Rep: Reputation: 0
PHP to mySQL array problem


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?

Any help greatfully received.
Mounters
 
Old 02-16-2002, 09:41 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
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" );

Header("Content-type: text/html");
print 
"<select size=7 name=\"TestMe\">\n";

$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");

?>
Output: (View source from browser)
Code:
<select size=7 name="TestMe">
<option value="five">5
<option value="one">1
<option value="ten">10
</select>
 
Old 02-17-2002, 03:36 AM   #3
mounters
LQ Newbie
 
Registered: Feb 2002
Location: England
Distribution: SuSE 7.3 prof
Posts: 9

Original Poster
Rep: Reputation: 0
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
 
Old 02-17-2002, 04:20 PM   #4
mounters
LQ Newbie
 
Registered: Feb 2002
Location: England
Distribution: SuSE 7.3 prof
Posts: 9

Original Poster
Rep: Reputation: 0
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP/MySQL Problem! SpiderIRE Programming 3 10-19-2005 11:24 AM
php-mysql problem need help productive Linux - Software 1 04-28-2005 02:27 PM
Problem with MySQL 4.1.7 and PHP 5.0.2 Lars79 Slackware 4 10-28-2004 08:09 AM
Problem getting PHP to recognize MySQL, Using PHP 4.0 and MySQL 4.0.20 d2army Programming 4 06-27-2004 08:54 PM
PHP: Multidimensional array problem lhoff Programming 1 06-10-2002 02:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration