Link to home
Start Free TrialLog in
Avatar of lienny
lienny

asked on

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
Avatar of mag1c1an
mag1c1an

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
Avatar of lienny

ASKER

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
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
Avatar of lienny

ASKER

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...
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
Avatar of lienny

ASKER

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.
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...
ASKER CERTIFIED SOLUTION
Avatar of Diablo84
Diablo84

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lienny

ASKER

not working...just passing the ,
Avatar of lienny

ASKER

that's alright...I'll look at the code tonite...and if it doesn't work...I'll bug you tomorrow or something. =D
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>
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
Avatar of lienny

ASKER

diablo,  thanks for your help AGAIN!  Got it to work.