...

View Full Version : I need help quickly



jeannepo
03-16-2007, 01:49 AM
Hi,

I've got an order form I'm trying to pass checkbox variable information, for EACH product purchased. I'm trying to email each checkbox selected, for each product.

My code looks like this (very simple) to build my email message:
$tmp = "";
for ($i = 1; $i <= $_POST["rowCount"]; $i++) {

if (strlen($_POST["INum".$i]) == 0)
continue;

$tmp .= " Card Type: {$_POST['IType'.$i]}\n";

// if ($_POST['IType'.$i] == "cards")
$tmp .= " Cards Chosen: {$_POST['ISize'.$i]}\n";
$tmp .= " Quantity: {$_POST['IQuan'.$i]}\n Total: {$_POST['IAmt'.$i]}\n\n";
}
$msgMessage .= $tmp;

My checkbox variables are the "cards chosen:" the variable ISize$i

I need a quick answer, I've worked on this for 3.5 days and need it done by tomorrow... HELP !!!

Many Thanks!

~jp

SpinCode
03-16-2007, 02:00 AM
As I know, there is no need for curly braces {} in your code. It's used only when you're creating a dynamic variable. Try removing them. :) It could be something else that I've missed, but give this a shot if its urgen.

Spin

jeannepo
03-16-2007, 02:06 AM
Hi,

I removed all the curly braces, now it doesn't process the page, at all.

:(

Nightfire
03-16-2007, 02:11 AM
What's this??


continue;

jeannepo
03-16-2007, 02:25 AM
I'm not sure what the continue; is for.

This code was originally written by someone else (you know how *that* goes) and I added the multiple checkboxes.

This script works, but the problem is it only returns ONE checkbox selection. I need to figure out how to get it to return ALL the checkboxes selected.

Tx for any help.

~jp

CFMaBiSmAd
03-16-2007, 02:40 AM
If you post your form code it will help in figuring out what data this code is operating on. Also, having the big picture might suggest a simpler way of doing this.

jeannepo
03-16-2007, 02:51 AM
My script works, with the exception of the line that you see "cards chosen" This form field is 20 checkboxes, and it's only giving me ONE result, per card, even when you check many more.

I just need to know how to make this script give me ALL the chosen checkbox selected for this one variable.

tx.

CFMaBiSmAd
03-16-2007, 03:22 AM
You can also echo out all of the $_POST array to see what it really contains -

<?php
echo "<pre>";
print_r($_POST);
echo "</pre>";
?>

SpinCode
03-16-2007, 12:32 PM
Apparently, the continue statement skips the current loop and proceeds to the next loop if the quantity is zero.

if (strlen($_POST["INum".$i]) == 0)
continue;

Since you mention that your system returns only 1 result, no matter what, then either $_POST["rowCount"] is just set to 1 by means of a html form hidden value or else $_POST["INum".$i] equals to zero and this value was not properly set through javascript on the client end.

How did removing curly braces halted execution ? Try it again, this way:

$tmp = "";
for ($i = 1; $i <= $_POST["rowCount"]; $i++) {

if (strlen($_POST["INum".$i]) == 0)
continue;

$tmp .= " Card Type: " . $_POST['IType'.$i] . "\n";

// if ($_POST['IType'.$i] == "cards")
$tmp .= " Cards Chosen: " . $_POST['ISize'.$i] . "\n";
$tmp .= " Quantity: " . $_POST['IQuan'.$i] ." \n Total: " . $_POST['IAmt'.$i] . "\n\n";
}
$msgMessage .= $tmp;


But if it's really urgent, then you definitely need to post more info than this code scrap here.

Spin

KeZZeR
03-16-2007, 12:47 PM
What's this??


continue;


There are two operations used to get out of a loop; break, and continue. Continue will just continue on to the next iteration whereas break will break out of the loop.

In this instance it's not needed because there's just a simple if statement in the middle of nowhere ;)

SpinCode
03-16-2007, 12:50 PM
There are two operations used to get out of a loop; break, and continue. Continue will just continue on to the next iteration whereas break will break out of the loop.

In this instance it's not needed because there's just a simple if statement in the middle of nowhere ;)

???? Isn't the if statement within the loop ? That it checks

if (strlen($_POST["INum".$i]) == 0)
continue;

the POST variable which is sequenced by $i if its zero ?

KeZZeR
03-16-2007, 01:17 PM
Yes sorry, my bad. I didn't look at the code properly

Yes, when the if statement is true it will continue directly onto the next iteration of the loop as opposed to executing the rest of the code. So anything after that if statement won't be executed if the if statement is true.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum