• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 469
  • Last Modified:

explode

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
lienny
Asked:
lienny
  • 6
  • 6
1 Solution
 
mag1c1anCommented:
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
 
liennyAuthor Commented:
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
 
Diablo84Commented:
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
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
liennyAuthor Commented:
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
 
Diablo84Commented:
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
 
liennyAuthor Commented:
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
 
Diablo84Commented:
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
 
Diablo84Commented:
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
 
liennyAuthor Commented:
not working...just passing the ,
0
 
liennyAuthor Commented:
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
 
Diablo84Commented:
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
 
Diablo84Commented:
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
 
liennyAuthor Commented:
diablo,  thanks for your help AGAIN!  Got it to work.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now