Advertisement

04.30.2008 at 08:03AM PDT, ID: 23365569
[x]
Attachment Details

insert array into mysql

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.7
Tags:

php, mysql

hello. i have a form that posts results to a processing page and i need to insert an array into mysql from this page. however, i am having trouble with an array. code below.

th idea is say someone enters items in the form. this is then passed to page 2 and inserted into db. so in the example, 3 items are being passed to page 2 and need to go into custref as seperate items if i insert at the moment, all items are inserted in 1 field. i also need to increment the btref field for each insert. so if before insert the value of btref is 4567 i need that to inc for each insert. thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
FORM PAGE
--------------------------------
<select name="box_ret[]" size="5" multiple="multiple" id="box_ret" wdg:subtype="DependentDropdown" wdg:type="widget" wdg:recordset="Recordset2" wdg:displayfield="custref" wdg:valuefield="custref" wdg:fkey="department" wdg:triggerobject="dept">
</select>
 
 
RESULTS PAGE
-----------------------------------------------------------
 
<?php 
 
if (isset($_POST['box_ret'])) {
// extract the array of list choices from the post data
	 $box_ret = $_POST['box_ret'];
  
	  $numChoices = count($box_ret);
	  $insertVal = "";
	 
	  for($i = 0; $i < $numChoices; $i++) {
// concatenate each array value to one string variable
	  $insertVal .= $box_ret[$i];
   
// put a comma after all but the last value
    if($i != $numChoices - 1) {
     $insertVal .= ",";
	 }
	 }
	echo 'Box(es) Selected: ' . '<span style="font-weight:bold;color: #000;">' . $insertVal . '</span>' . '<p />'; }
	elseif ($insertVal <= 0) {
	echo '<span class="stop_error">' . 'You haven\'t chosen a box. you must select a box' . '</span>' . '<p />';}
	$_SESSION['box_ret'] = $_POST['box_ret'];
?>
 
MYSQL
-----------------------------------------------------
 
mysql_query("INSERT INTO boxes (customer, department, status, custref, btref) VALUES('$name', '$dept', '9', '$custref', $btref)") 
or die(mysql_error());
 
Expert Comment by Ray_Paseur:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by Ray_Paseur:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by Ray_Paseur:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by peter_coop:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by Ray_Paseur:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by peter_coop:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by peter_coop:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Accepted Solution by infernoza:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by peter_coop:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
20081119-EE-VQP-45 / EE_QW_2_20070628