/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] for each array problem

Hey peeps,

I have a form which has checkboxes and textboxes.

Im trying to make a for each to duplicate all the data appart from one cell and make a new insert for every checkbox that has been checked:

for each checkbox that has been checked insert into the database. so it’ll look something like this

col1 col2 col3
1 2 3
1 2 5
1 2 9

Here how far its come:

[code=php]

<?php
echo ‘<p> post places: ‘ . $_POST[‘place’] . ‘</p>’;
$places_array = explode (‘,’ , $places);
echo ‘<p> places array: ‘ . print_r($places_array) . ‘</p>’;

foreach($places_array as $place_entry){
str_replace(“‘”, “”, $place_entry, $count);
echo $place_entry;
echo $count;
}

$insert = “INSERT INTO activities (`date`, `email`, `place`) VALUES (‘”.$daf.”‘,'”.$email.”‘,'”.$place_entry.”‘,'”)”;
$add_activity = mysql_query($insert);
if($add_activity == false) {
$error = mysql_error();
die(“<pre>”.$error.”n$insert</pre>”);
}

?>

[/code]

This is what it prints out

post places: elm, fir

Array ( [0] => elm [1] => fir )
places array: 1

elm0 fir0

How would you make this work?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@swl7authorNov 28.2012 — I made it insert into the database the way i want BUT it leaves all the other fields blank HELP

THanks ?
×

Success!

Help @swl7 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...