?
Solved

explode

Posted on 2004-08-02
13
Medium Priority
?
465 Views
Last Modified: 2013-12-12
i'm inserting the value into my db, but i would like the name of the field to be pass in the e-mail
would i use explode for this?

<input type="checkbox" value="1" name="exterior[]">Front Bumper
0
Comment
Question by:lienny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
13 Comments
 
LVL 2

Expert Comment

by:mag1c1an
ID: 11699811
Can you explain this a bit further?
Your question is a bit confusing and for the points you are offering, you are not going to get many answers.

Cheers,
-Mag
0
 

Author Comment

by:lienny
ID: 11700085
i have about 30 checkboxes on my form...all with different values...I use the values to insert into my db.
$exterior = $_POST['exterior'];
if (is_array($exterior)) {
  $ext = implode(',', $exterior);
} else
  $ext = $exterior;

so something like this would get inserted into the db field 1,4,30
when the form is submitted it gets inserted into the db and also, e-mail to myself so that I know what kind of damages there are.  I would like for it to pass the input name instead of the array of numbers...that way I don't have to go back to the db to figure out what number corresponds with what damages.  I hope this is clear.

<input type="checkbox" value="1" name="exterior[]">Front Bumper
input type="checkbox" value="2" name="exterior[]">Roof
input type="checkbox" value="3" name="exterior[]">Rear Window
input type="checkbox" value="4" name="exterior[]">F. Wheel, Driv. Side
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 11700206
how about this, after

$exterior = $_POST['exterior'];

add:

$arr = "";
foreach ($exterior as $key => $var) {
$arr .= "\$exterior['$key'] = $var<br>\n";
}

you can then send the variable $arr in your mail

sample output (using the checkbox code you provided) ->

$exterior['0'] = 1
$exterior['1'] = 2
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:lienny
ID: 11700222
diablo...coming to my rescue again...
no that won't work...i want to pass the string into the mail...
just like how we did the location...
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 11700244
confused :S

>> i want to pass the string into the mail...

the variable $arr contains the values in a string as shown in the example above

so if the first two checkboxes are checked $arr will contain the string

"$exterior['0'] = 1
$exterior['1'] = 2"

which can then be inserted in your mail messgae using the way i showed before

$message = "other message stuff and $arr";

If thats not what your looking for could you elaborate more on what you want to achieve, ie. what information you want included in the mail (in the sense of its structure/layout).

Diablo
0
 

Author Comment

by:lienny
ID: 11700257
if they user chooses the 1st and 2nd checkbox it'll get a 1,2 inserted into the db.

when that is done...i'd like the e-mail to contain front bumper, roof instead of the values 1,2.
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 11700263
oh i see, well thats not a problem but its going to mean some modification to your code and possibly your query

code to follow...
0
 
LVL 27

Accepted Solution

by:
Diablo84 earned 500 total points
ID: 11700299
your check box values will have to contain the text in the value as well as the number seperated by | ie.

<input type="checkbox" value="1|Front Bumper" name="exterior[]">Front Bumper<br>
<input type="checkbox" value="2|Roof" name="exterior[]">Roof<br>
<input type="checkbox" value="3|Rear Window" name="exterior[]">Rear Window<br>
<input type="checkbox" value="4|F. Wheel, Driv. Side" name="exterior[]">F. Wheel, Driv. Side<br>

then the php will have to be changed to the following:

$exterior = $_POST['exterior'];
if (is_array($exterior)) {
 foreach ($exterior as $var) {
  $pre = explode("|",$var);
  $arr[] = $pre[0];
  $arr2[] = $pre[1];
 }
 $ext = implode(',', $arr);
 $mailext = implode(',', $arr2);
}
else {
 $ext = $exterior;
}

This is untested and off the top of my head but it should *touch wood* do the job fine and mean that you dont have to alter any more of your code. use the variable $mailext in your mail to send the text values

any problems let me know, im off to bed in 15 minutes so if you need any more help tonight test asap if possible :)
0
 

Author Comment

by:lienny
ID: 11700327
not working...just passing the ,
0
 

Author Comment

by:lienny
ID: 11700335
that's alright...I'll look at the code tonite...and if it doesn't work...I'll bug you tomorrow or something. =D
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 11700345
well might as well try and wrap this one up if possible tonight :)

have you updated the checkboxes? i just set up a test script to check it and it works for me >>

<?php
$exterior = $_POST['exterior'];
if (is_array($exterior)) {
 foreach ($exterior as $var) {
  $pre = explode("|",$var);
  $arr[] = $pre[0];
  $arr2[] = $pre[1];
 }
 $ext = implode(',', $arr);
 $mailext = implode(',', $arr2);
}
else {
 $ext = $exterior;
}

echo $ext;
echo"<br>";
echo $mailext;
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="checkbox" value="1|Front Bumper" name="exterior[]">Front Bumper<br>
<input type="checkbox" value="2|Roof" name="exterior[]">Roof<br>
<input type="checkbox" value="3|Rear Window" name="exterior[]">Rear Window<br>
<input type="checkbox" value="4|F. Wheel, Driv. Side" name="exterior[]">F. Wheel, Driv. Side<br>
<input type="submit">
</form>
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 11700380
i am dissapearing now for tonight

i suspect/hope that as the code works fine for me that it is a minor error you have made implementing it in your script in which case you should be able to sort it without needing any assistance.

If you do have problems still don't hesitate to ask, il check this thread again in the morning.

Good luck.

Diablo
0
 

Author Comment

by:lienny
ID: 11700436
diablo,  thanks for your help AGAIN!  Got it to work.
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question