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 6 of 6

Thread: frustration!!!

  1. #1
    New to the CF scene
    Join Date
    May 2008
    Location
    west coast of canada
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    frustration!!!

    so here is my php
    PHP Code:
    <?php
    //This is a very simple PHP script that outputs the name of each bit of information (that corresponds to the <code>name</code> attribute for that field) along with the value that was sent with it right in the browser window, and then sends it all to an email address (once you've added it to the script).

    if (empty($_POST)) {
        print 
    "<p>No data was submitted.</p>";
        print 
    "</body></html>";
        exit();
    }

    //Creates function that removes magic escaping, if it's been applied, from values and then removes extra newlines and returns to foil spammers. Thanks Larry Ullman!
    function clear_user_input($value) {
        if (
    get_magic_quotes_gpc()) $value=stripslashes($value);
        
    $valuestr_replace"\n"''trim($value));
        
    $valuestr_replace"\r"''$value);
        return 
    $value;
        }


    if (
    $_POST['comments'] == 'Please share any comments you have here'$_POST['comments'] = '';    

    //Create body of message by cleaning each field and then appending each name and value to it

    $body ="Here is the data that was submitted:\n";
    $magnetic_thoughts = array( ma01 => "ma01",
                    
    ma02 => "ma02",
                    
    ma03 => "ma03",
                    
    ma04 => "ma04"
                       
    ma05 => "ma05"
                    
    mb01 => "mb01",
                    
    mb03 => "mb03"
                    
    mb04 => "mb04",
                    
    mb05 => "mb05",
                    
    mb06 => "mb06"
                    
    mb07 => "mb07",
                    
    mc01 => "mc01",
                    
    md01 => "md01",
                    
    md02 => "md02",
                    
    md03 => "md03"
                    
    md04 => "md04",
                    
    mf01 => "mf01"
                    
    mf02 => "mf02",
                    
    mh01 => "mh01"
                    
    mi01 => "mi01"
                    
    mi02 => "mi02"
                    
    mi03 => "mi03"
                    
    mi04 => "mi04"
                    
    mj01 => "mj01"
                    
    mk01 => "mk01"
                    
    ml01 => "ml01",
                    
    ml02 => "ml02",
                    
    ml03 => "ml03"
                    
    ml04 => "ml04"
                    
    ml05 => "ml05"
                    
    ml06 => "ml06"
                    
    ml07 => "ml07",
                    
    ml08 => "ml08"
                    
    ml09 => "ml09",
                    
    ml10 => "ml10"
                    
    ml11 => "ml11"
                    
    mm01 => "mm01",
                    
    mn01 => "mn01"
                    
    mn02 => "mn02"
                    
    mp01 => "mp01",
                    
    mp02 => "mp02",
                    
    mr01 => "mr01"
                    
    ms01 => "ms01",
                    
    ms02 => "ms02"
                    
    ms03 => "ms03"
                    
    mt01 => "mt01"
                    
    mt02 => "mt02",
                    
    mt03 => "mt03"
                    
    mt04 => "mt04",
                    
    mt05 => "mt05"
                    
    mt06 => "mt06",
                    
    mt07 => "mt07"
                    
    mw02 => "mw02",
                    
    mw03 => "mw03",
                    
    mw04 => "mw04",
                    
    my01 => "my01",
                    
    my02 => "my02",
                    
    my03 => "my03",
                    
    my04 => "my04",
                    
    my05 => "my05",
                    
    my06 => "my06"
    ); 


    $magnetic_thoughts $_POST["magnetic_thoughts"];

    if (
    is_array($magnetic_thoughts)) {
       foreach (
    $magnetic_thoughts as $key => $value) {
        print 
    "ordering these $value magnetic thoughts.<br>";
        }
    }

    foreach (
    $_POST as $key => $value) {
        
    $key clear_user_input($key);
        
    $value clear_user_input($value);
        if (
    $key=='extras') {
            
        if (
    is_array($_POST['extras']) ){
            
    $body .= "$key: ";
            
    $counter =1;
            foreach (
    $_POST['extras'] as $value) {
                    
    //Add comma and space until last element
                    
    if (sizeof($_POST['extras']) == $counter) {
                        
    $body .= "$value\n";
                        break;}
                    else {
                        
    $body .= "$value, ";
                        
    $counter += 1;
                        }
                    }
            } else {
            
    $body .= "$key: $value\n";
            }
        } else {

        
    $body .= "$key: $value\n";
        }
    }

    extract($_POST);
    //removes newlines and returns from $email and $name so they can't smuggle extra email addresses for spammers
    $email clear_user_input($email);
    $name clear_user_input($name);

    //Create header that puts email in From box along with name in parentheses and sends bcc to alternate address
    $from='From: '$email "(" $name ")" "\r\n" 'Bcc: ceri@bcwineguys.com' "\r\n";


    //Creates intelligible subject line that also shows me where it came from
    $subject 'product order from web site';

    //Sends mail to me, with elements created above
    mail ('ceri@bcwineguys.com.com'$subject$body$from);


    ?>
    everything works except when the email order comes to my inbox it says:


    Here is the data that was submitted:
    name:
    address:
    phone_number:
    city:
    prov/state:
    email:
    magnetic_thoughts: Array

    why does the order not come to my email. the selected checkboxes don't return any info.

    help!!!!!

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    I don't see where you're getting $_POST['magnetic_thoughts'], but presumably it's from an array of checkboxes.

    In that case,
    Code:
    foreach ($_POST as $key => $value)
    is doing it's job. It's pulling the $key as 'magnetic_thoughts' and the $value as Array - which is what it is.

  • #3
    New to the CF scene
    Join Date
    May 2008
    Location
    west coast of canada
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok so do you mean that i should replace this line
    PHP Code:
    foreach ($magnetic_thoughts as $key => $value
    with the one you suggested or should i ADD that line.

  • #4
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    I didn't suggest any code, the line I posted was taken from your code.

    Code:
    foreach ($_POST as $key => $value) {
        $key = clear_user_input($key);
        $value = clear_user_input($value);
        if ($key=='extras') {
            
        if (is_array($_POST['extras']) ){
            $body .= "$key: ";
            $counter =1;
            foreach ($_POST['extras'] as $value) {
                    //Add comma and space until last element
                    if (sizeof($_POST['extras']) == $counter) {
                        $body .= "$value\n";
                        break;}
                    else {
                        $body .= "$value, ";
                        $counter += 1;
                        }
                    }
            } else {
            $body .= "$key: $value\n";
            }
        } else {
    
        $body .= "$key: $value\n";
        }
    }
    What I'm saying, is the output you are getting is exactly what the above code is doing.

    If, the magnetic_thoughts are coming from an array of checkboxes (which you didn't bother to address), and you want the values to be displaying in your email, you are going to have to loop through the magnetic_thoughts array, parse each value and add it to your $body

    BTW, in this code:
    Code:
    $magnetic_thoughts = array( ma01 => "ma01",
                    ma02 => "ma02",
                    ma03 => "ma03",
                    ma04 => "ma04", 
                       ma05 => "ma05", 
                    mb01 => "mb01",
                    mb03 => "mb03", 
                    mb04 => "mb04",
                    mb05 => "mb05",
                    mb06 => "mb06", 
                    mb07 => "mb07",
                    mc01 => "mc01",
                    md01 => "md01",
                    md02 => "md02",
                    md03 => "md03", 
                    md04 => "md04",
                    mf01 => "mf01", 
                    mf02 => "mf02",
                    mh01 => "mh01", 
                    mi01 => "mi01", 
                    mi02 => "mi02", 
                    mi03 => "mi03", 
                    mi04 => "mi04", 
                    mj01 => "mj01", 
                    mk01 => "mk01", 
                    ml01 => "ml01",
                    ml02 => "ml02",
                    ml03 => "ml03", 
                    ml04 => "ml04", 
                    ml05 => "ml05", 
                    ml06 => "ml06", 
                    ml07 => "ml07",
                    ml08 => "ml08", 
                    ml09 => "ml09",
                    ml10 => "ml10", 
                    ml11 => "ml11", 
                    mm01 => "mm01",
                    mn01 => "mn01", 
                    mn02 => "mn02", 
                    mp01 => "mp01",
                    mp02 => "mp02",
                    mr01 => "mr01", 
                    ms01 => "ms01",
                    ms02 => "ms02", 
                    ms03 => "ms03", 
                    mt01 => "mt01", 
                    mt02 => "mt02",
                    mt03 => "mt03", 
                    mt04 => "mt04",
                    mt05 => "mt05", 
                    mt06 => "mt06",
                    mt07 => "mt07", 
                    mw02 => "mw02",
                    mw03 => "mw03",
                    mw04 => "mw04",
                    my01 => "my01",
                    my02 => "my02",
                    my03 => "my03",
                    my04 => "my04",
                    my05 => "my05",
                    my06 => "my06", 
    ); 
    
    
    $magnetic_thoughts = $_POST["magnetic_thoughts"];
    The line $magnetic_thoughts = $_POST["magnetic_thoughts"]; is overwriting the array you created immediately before it.
    Last edited by PappaJohn; 05-14-2008 at 11:38 PM. Reason: typo

  • #5
    New to the CF scene
    Join Date
    May 2008
    Location
    west coast of canada
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thankyou for helping me, i'm sorry if this is just me being totally inexperienced.

    how do i address the array of checkboxes, and where should i be putting the array?

    i am using a combination of code from a book and from a class.

    i am so stuck

  • #6
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    $magnetic_thoughts = $_POST["magnetic_thoughts"]; will get the array of checkboxes ie: $magnetic_thoughts will be an array of the values.

    Inside the loop where you build your $body you will need to loop through the $magnetic_thoughts array.

    I understand inexperience, but I do not agree with simply copying / pasting code which you do not understand. Based on your questions, I strongly suspect you don't understand what the code is doing.

    I suggest you do some research and figure out what the code you posted is doing. Then, you can figure out how to accomplish what I posted above. Otherwise, simply posting working code for you to copy/paste is not helping you, and will only cause more problems later.


  •  

    Posting Permissions

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