/    Sign up×
Community /Pin to ProfileBookmark

check box help :php

ok i got a number of check boxes and it works fine with one checked but if i check a multiple i only get the last check box….

[CODE]
<div id=”formNumber1″ style=”display:none;”>
<input type=”checkbox” name=”checkbox” value=”yt”>Youtube<br />
Url 1: <input type=”text” name=”yurl”><br />
Url 2: <input type=”text” name=”yurl1″><br />
Url 3: <input type=”text” name=”yurl2″><br />
</div>

<div id=”formNumber2″ style=”display:none;”>
<input type=”checkbox” name=”checkbox” value=”my”>Myspace<br />
Url 1: <input type=”text” name=”murl”><br />
Url 2: <input type=”text” name=”murl1″><br />
Url 3: <input type=”text” name=”murl2″><br />
</div>
[/CODE]

if i check “Youtube” i get yt but if i check both “Youtube” & “Myspace” i get only “my”.

php side

[CODE]

$type=$_POST[‘checkbox’];

after that i have a few if statements….
[/CODE]

I also want to ask about mysql… see i want php to create a page when the user has filled out the form (which i have achieved) but i want the page to have a player code in it with the the playlist (which will also be created by php) that will have links to their videos in it…

example :

[CODE]
<script type=’text/javascript’ src=’player/swfobject.js’></script>

<div id=’mediaspace’>This text will be replaced</div>

<script type=’text/javascript’>
var so = new SWFObject(‘player/player.swf’,’mpl’,’100%’,’90%’,’9′);
so.addParam(‘allowfullscreen’,’true’);
so.addParam(‘allowscriptaccess’,’always’);
so.addParam(‘wmode’,’opaque’);
so.addVariable(‘playlistfile’,'[COLOR=”Red”]playlist/newe.xml[/COLOR]’);
so.addVariable(‘playlistsize’,’120′);
so.addVariable(‘playlist’,’right’);
so.addVariable(‘repeat’,’list’);
so.addVariable(‘autostart’,’true’);
so.write(‘mediaspace’);
</script>

<script type=’text/javascript’ src=’player/swfobject.js’></script>
[/CODE]

i want to replace the playlist location with the playlist the user created….

how can i do this in mysql.. and how do i extract the right playlist from the database as the user will not be logged in… or can i do it without a database?

sorry for the long post… any help appreciated.

to post a comment
PHP

15 Comments(s)

Copy linkTweet thisAlerts:
@tirnaJul 22.2010 — if you have multiple checkboxes with the same name, you need to send them to the server as an array.

[CODE]
<input type="checkbox" name="myChkBox[COLOR=red][][/COLOR]" value="yt" />
<input type="checkbox" name="myChkBox[COLOR=red][][/COLOR]" value="my" />
[/CODE]


and then on the server

[CODE]$myChkBoxes = $_POST['myChkBox'];[/CODE]

$myChkBoxes will be an array of all the values from the checked checkboxes.
Copy linkTweet thisAlerts:
@gazzamcauthorJul 23.2010 — if you have multiple checkboxes with the same name, you need to send them to the server as an array.

[CODE]
<input type="checkbox" name="myChkBox[COLOR=red][][/COLOR]" value="yt" />
<input type="checkbox" name="myChkBox[COLOR=red][][/COLOR]" value="my" />
[/CODE]


and then on the server

[CODE]$myChkBoxes = $_POST['myChkBox'];[/CODE]

$myChkBoxes will be an array of all the values from the checked checkboxes.[/QUOTE]

tnx i'll try that..
Copy linkTweet thisAlerts:
@tirnaJul 23.2010 — you're welcome - happy to help ?
Copy linkTweet thisAlerts:
@gazzamcauthorJul 23.2010 — you're welcome - happy to help ?[/QUOTE]

ok i gave it a try....

i echoed out $myChkBoxes and all i got was array not 'yt' or 'my' ...

i copied your code exactly..
Copy linkTweet thisAlerts:
@tirnaJul 23.2010 — with $myChkBoxes in the php script being an array I hope you use a FOR or FOREACH loop to echo the elements in the array and not:

echo $myChkBoxes;
Copy linkTweet thisAlerts:
@gazzamcauthorJul 23.2010 — with $myChkBoxes in the php script being an array I hope you use a FOR or FOREACH loop to echo the elements in the array and not:

echo $myChkBoxes;[/QUOTE]


no i didn't use FOR or FOREACH loop , i'm a total newb at php lol
Copy linkTweet thisAlerts:
@tirnaJul 23.2010 — [code=php]
<?php

foreach($myChkBoxes as $value) {
echo $value.'<br />';
}

die();

?>
[/code]
Copy linkTweet thisAlerts:
@gazzamcauthorJul 23.2010 — [code=php]
<?php

foreach($myChkBoxes as $value) {
echo $value.'<br />';
}

die();

?>
[/code]
[/QUOTE]


it worked.. tnx.. sorry for the trouble...
Copy linkTweet thisAlerts:
@tirnaJul 23.2010 — no problem - happy to help ?
Copy linkTweet thisAlerts:
@gazzamcauthorJul 23.2010 — no problem - happy to help ?[/QUOTE]

sorry to trouble you again but i have the same prob as before... only the last checked shows...
Copy linkTweet thisAlerts:
@tirnaJul 23.2010 — If you can, post your current html and php code in the next few minutes as I will have to go after that.

If you have the square brackets [] after the name in each checkbox as I posted earlier then it should work unless there is something else going in your code.
Copy linkTweet thisAlerts:
@gazzamcauthorJul 23.2010 — If you can, post your current html and php code in the next few minutes as I will have to go after that.

If you have the square brackets [] after the name in each checkbox as I posted earlier then it should work unless there is something else going in your code.[/QUOTE]


sorry about this it looks like i made a typo mistake..

<i>
</i>$myChkBoxes = $_POST['myChkBox'];



foreach($myChkBoxes as $value) {
echo $value.'&lt;br /&gt;'; die();
}


i had something like above... it's all good now.. thanks very much for your help.
Copy linkTweet thisAlerts:
@tirnaJul 23.2010 — This test code works on my local server so I assume there must be something else going on somewhere in your code but I can't see it at the moment.

I removed the display: none styles you have on those 2 divs.

I'll have another look tomorrow.

[CODE]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd[/URL]">
<html xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]">
<head>
<title></title>
</head>
<body>

<form action="test.php" method="post" />
<div id="formNumber1">
<input type="checkbox" name="myChkBox[]" value="yt" />Youtube<br />
Url 1: <input type="text" name="yurl"><br />
Url 2: <input type="text" name="yurl1"><br />
Url 3: <input type="text" name="yurl2"><br />
</div>

<div id="formNumber2">
<input type="checkbox" name="myChkBox[]" value="my" />Myspace<br />
Url 1: <input type="text" name="murl"><br />
Url 2: <input type="text" name="murl1"><br />
Url 3: <input type="text" name="murl2"><br />
</div>

<input type="submit" value="Submit" />

</form>

</body>
</html>
[/CODE]


and the php


[CODE]
<?php

$myChkBoxes = $_POST['myChkBox'];
foreach($myChkBoxes as $value) {
echo $value.'<br />';
}
die();

?>
[/CODE]


outputs yt and my when I click both checkboxes and submit the form.
Copy linkTweet thisAlerts:
@tirnaJul 23.2010 — it's all good now.. thanks very much for your help.[/quote]

No problem - I'm glad you sorted it out in the end - I can sleep easy now :eek:

Good night ?
Copy linkTweet thisAlerts:
@gazzamcauthorJul 23.2010 — No problem - I'm glad you sorted it out in the end - I can sleep easy now :eek:

Good night ?[/QUOTE]


no problem goodnight..
×

Success!

Help @gazzamc 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...