Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 18th, 2005, 09:32 PM
Registered User
 
Join Date: Jan 2005
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.

 
Old June 21st, 2005, 10:13 AM
Friend of Wrox
 
Join Date: Jul 2003
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.






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





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