Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy I need help quickly

    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

  • #2
    New Coder
    Join Date
    Jan 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

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


  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    What's this??
    PHP Code:
    continue; 

  • #5
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,044
    Thanks
    2
    Thanked 316 Times in 308 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #7
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #8
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,044
    Thanks
    2
    Thanked 316 Times in 308 Posts
    You can also echo out all of the $_POST array to see what it really contains -
    PHP Code:
    <?php
    echo "<pre>";
    print_r($_POST);
    echo 
    "</pre>";
    ?>
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #9
    New Coder
    Join Date
    Jan 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #10
    Regular Coder
    Join Date
    Oct 2004
    Location
    England
    Posts
    282
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Nightfire View Post
    What's this??
    PHP Code:
    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

  • #11
    New Coder
    Join Date
    Jan 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by KeZZeR View Post
    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 ?

  • #12
    Regular Coder
    Join Date
    Oct 2004
    Location
    England
    Posts
    282
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •