Solved

explode

Posted on 2004-08-02
13
457 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
  • 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 125 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now