Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 04-18-2009, 03:45 PM   PM User | #1
jessnoonyes
Regular Coder

 
Join Date: Mar 2007
Posts: 151
Thanks: 6
Thanked 4 Times in 4 Posts
jessnoonyes is on a distinguished road
php explode

Hi guys. I've been getting help in the javascript forum putting together a php/javascript quiz. I had it functioning ok but it wasn't working in IE7 and they helped me rewrite it. However, before I had the variables being passed in hidden checkboxes. Now there are no checkboxes and I'm struggling with php explode as the javascript guys suggested I use.

What am I doing wrong?

Code:
<form action="money_quiz_results.php"  method="post">
<input type="hidden" name="userSelections">
Code:
<tr>
				<td>Anxious</td>
				<td>Prone to blame</td>
				<td>Highly Emotional</td>
			</tr>
			<tr>
				<td>Lives in the past</td>
				<td>Financially irresponsible</td>
				<td>Seeks rescue</td>
			</tr>
on the results page:

PHP Code:
<?php
$userSelections 
explode(";"); 

$innocent 0;
if (
$_POST['anxious'] == 'yes')
$innocent++;
if (
$_POST['trusting'] == 'yes')
$innocent++;
if (
$_POST['feels_powerless'] == 'yes')
$victim++;
if (
$_POST['financially_irrisponsible'] == 'yes')
$victim++;
if (
$_POST['seeks_rescue'] == 'yes')
$victim++; .....
jessnoonyes is offline   Reply With Quote
Old 04-18-2009, 04:12 PM   PM User | #2
soak
New Coder

 
Join Date: Apr 2009
Posts: 17
Thanks: 0
Thanked 2 Times in 2 Posts
soak is an unknown quantity at this point
If you don't have any checkboxes then you won't have any form data to capture in your page.
soak is offline   Reply With Quote
Old 04-18-2009, 04:23 PM   PM User | #3
venegal
Regular Coder

 
Join Date: Apr 2009
Posts: 700
Thanks: 1
Thanked 163 Times in 163 Posts
venegal will become famous soon enoughvenegal will become famous soon enough
In your Javascript thread 12 Pack Mack mentioned that with his code your variables would be passed within the userSelections field as a comma delimited string, meaning what you have to do is:

$userSelections = explode(",", $_POST['userSelections']);

$userSelections will then be an array holding your variables.
venegal is offline   Reply With Quote
Old 04-18-2009, 04:39 PM   PM User | #4
jessnoonyes
Regular Coder

 
Join Date: Mar 2007
Posts: 151
Thanks: 6
Thanked 4 Times in 4 Posts
jessnoonyes is on a distinguished road
Awesome, thanks for helping! I have the results page like this:

Code:
<?php
$userSelections = explode(",", $_POST['userSelections']);

$innocent = 0;
if ($_POST['anxious'] == 'yes')
$innocent++;
if ($_POST['trusting'] == 'yes')
$innocent++;
But it isn't showing anything. Here's my test page. Only the first few items have been changed but you'll see if you click on them no results are shown on the next page. What did I do wrong?

Last edited by JohnDubya; 04-28-2009 at 04:35 PM.. Reason: remove url, as requested
jessnoonyes is offline   Reply With Quote
Old 04-18-2009, 06:57 PM   PM User | #5
venegal
Regular Coder

 
Join Date: Apr 2009
Posts: 700
Thanks: 1
Thanked 163 Times in 163 Posts
venegal will become famous soon enoughvenegal will become famous soon enough
$_POST will only contain 'userSelections', which should contain all your variables, so calling $_POST['something else'] doesn't do anything. Try echo var_dump($userSelection); in order to see what's in there and how you can use it.
venegal is offline   Reply With Quote
Old 04-18-2009, 09:22 PM   PM User | #6
jessnoonyes
Regular Coder

 
Join Date: Mar 2007
Posts: 151
Thanks: 6
Thanked 4 Times in 4 Posts
jessnoonyes is on a distinguished road
It says NULL
jessnoonyes is offline   Reply With Quote
Old 04-18-2009, 09:52 PM   PM User | #7
soak
New Coder

 
Join Date: Apr 2009
Posts: 17
Thanks: 0
Thanked 2 Times in 2 Posts
soak is an unknown quantity at this point
The results page is working for me:

On the left you can see the post data that was sent.
Attached Thumbnails
Click image for larger version

Name:	working.jpg
Views:	47
Size:	40.9 KB
ID:	7327  
soak is offline   Reply With Quote
Old 04-18-2009, 11:01 PM   PM User | #8
jessnoonyes
Regular Coder

 
Join Date: Mar 2007
Posts: 151
Thanks: 6
Thanked 4 Times in 4 Posts
jessnoonyes is on a distinguished road
Hey awesome! Why won't it do that for me? It won't work in either Firefox or IE7. The values are always zero and the var_dump says NULL.

*the values will still be passed if there's a checkbox that's checked...
jessnoonyes is offline   Reply With Quote
Old 04-18-2009, 11:15 PM   PM User | #9
soak
New Coder

 
Join Date: Apr 2009
Posts: 17
Thanks: 0
Thanked 2 Times in 2 Posts
soak is an unknown quantity at this point
That was on linux but I've just tested on Windows XP, both firefox and IE7 and it works on both. There are some javascript errors still though.
soak is offline   Reply With Quote
Old 04-19-2009, 03:08 AM   PM User | #10
venegal
Regular Coder

 
Join Date: Apr 2009
Posts: 700
Thanks: 1
Thanked 163 Times in 163 Posts
venegal will become famous soon enoughvenegal will become famous soon enough
Sorry, I mistyped. echo var_dump($userSelections);

I didn't have a look through the Javascript code though, just the comment that went with it.

Last edited by venegal; 04-19-2009 at 03:12 AM.. Reason: typo
venegal is offline   Reply With Quote
Old 04-19-2009, 09:14 PM   PM User | #11
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 5,063
Thanks: 391
Thanked 600 Times in 589 Posts
oesxyl has a spectacular aura aboutoesxyl has a spectacular aura about
Quote:
Originally Posted by venegal View Post
Sorry, I mistyped. echo var_dump($userSelections);

I didn't have a look through the Javascript code though, just the comment that went with it.
var_dump return void
that echo is useless or I miss something and don't understand what you want to do.

best regards
oesxyl is offline   Reply With Quote
Old 04-19-2009, 11:22 PM   PM User | #12
venegal
Regular Coder

 
Join Date: Apr 2009
Posts: 700
Thanks: 1
Thanked 163 Times in 163 Posts
venegal will become famous soon enoughvenegal will become famous soon enough
You're right, thanks. Judging by the time I posted, I was probably drunk.
venegal is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:10 AM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.