Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 18th, 2005, 09:32 PM
Registered User
 
Join Date: Jan 2005
Location: Midlothian, VA, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Store Array of Form Values

I have a form with multiple select values that I would like to store in a database. I have named the array fields: area_mls[] and type_mls[]. This is the code I'm using...

  $insertSQL = sprintf("INSERT INTO mlsArea_mls (name_mls, state_mls, realtorID_mls, area_mls, type_mls)
  VALUES (%s, %s, %s,

  '" . join(",",$_POST["area_mls"]). "',
  '" . join(",",$_POST["type_mls"]). "'
  )",

                       GetSQLValueString($_POST['name_mls'], "text"),
                       GetSQLValueString($_POST['state_mls'], "text"),
                       GetSQLValueString($_POST['realtorID_mls'], "int"));

I get the following error messages...

Warning: join(): Bad arguments. in ../public_html/mlsArea.php on line 41

Warning: Cannot modify header information - headers already sent by (output started at ../public_html/mlsArea.php:41) in ../public_html/mlsArea.php on line 57

I'm thinking it's because the datatypes aren't correct for this type of join statement. It worked for me with a text field, but now I'm trying to store the id's of the values in an int field in mysql database.

I'm sure it's something simple, I'm just not familiar enough with PHP to know how to make it work.

Thanks for any help you can provide.

Reply With Quote
  #2 (permalink)  
Old June 21st, 2005, 10:13 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: York, , United Kingdom.
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Most likely, your second argument in the join, i.e. your $_POST["area_mls"] isn't an array. The probable reason for this is in the name for your select element.

If you've got a select element like this:
Code:
<select multiple="true" name="selList">
then in the $_POST['selList'] variable, you'll just have a single element, which is the last item selected in 'selList', even if there are multiple items selected.

To get around this, do the following:
Code:
<select multiple="true" name="selList[]">
This will mean that $_POST['selList'] is always an array, containing all selected items (it is still an array even if only one item was selected).

The only problem arises when no items are selected. In this case, $_POST['selList'] won't exist. What you need to do is use the array_key_exists function to check for the existence of the item you're after.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
passing Multidimensional Array Values back to form stitch Classic ASP Databases 2 June 21st, 2013 01:59 PM
Store time into Array derekl ASP.NET 1.0 and 1.1 Basics 3 December 18th, 2006 09:41 AM
can i store array values in a column using sqlser anil_76781 SQL Server 2000 1 May 10th, 2005 04:35 AM
Passing php array values to javascript array gkrishna Pro PHP 0 November 6th, 2004 03:20 AM



All times are GMT -4. The time now is 01:23 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.