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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    New Coder
    Join Date
    Sep 2007
    Posts
    59
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Easy question for php programmers, I just want to display form data after submitting.

    I just created a form that when submitted, it submits to register.php. This file connects to a sql database and then drops the data in and sends an email of the data. Everything works, and we're all good.

    What I want to do, is from this file, it directs to a form submitted successfully page. On this page, I want to display some of the data that was submitted in the form. How do I go about doing this?

    Here is what is in register.php

    <?php
    require 'functions.php';

    dbconnect();

    if ($_POST["Submit"]=="Submit")
    {
    //REGISTRATION INFO REQUIREMENTS
    if (!$name) { echo "Please <a href=javascript:history.go(-1)>go back</a> and fill in your <b>NAME.</B>"; exit(); }
    if (!$nadults) { echo "Please <a href=javascript:history.go(-1)>go back</a> and fill in your <b>LAST NAME.</B>"; exit(); }
    if (!$nchildren) { echo "Please <a href=javascript:history.go(-1)>go back</a> and fill in your <b>ORGANIZATION.</B>"; exit(); }
    if (!$adultages) { echo "Please <a href=javascript:history.go(-1)>go back</a> and fill in your <b>BUSINESS ADDRESS.</B>"; exit(); }
    if (!$childages) { echo "Please <a href=javascript:history.go(-1)>go back</a> and fill in your <b>BUSINESS CITY.</B>"; exit(); }
    if (!$contact) { echo "Please <a href=javascript:history.go(-1)>go back</a> and fill in your <b>BUSINESS STATE.</B>"; exit(); }
    if (!$address) { echo "Please <a href=javascript:history.go(-1)>go back</a> and fill in your <b>BUSINESS ZIP.</B>"; exit(); }
    if (!$city) { echo "Please <a href=javascript:history.go(-1)>go back</a> and fill in your <b>PHONE.</B>"; exit(); }

    if (!$state) { echo "Please <a href=javascript:history.go(-1)>go back</a> and fill in your <b>EMAIL.</B>"; exit(); }
    if (!$zip) { echo "Please <a href=javascript:history.go(-1)>go back</a> and fill in the <b>ZIP.</B>"; exit(); }
    if (!$phone) { echo "Please <a href=javascript:history.go(-1)>go back</a> and fill in the <b>TELEPHONE.</B>"; exit(); }
    if (!$email) { echo "Please <a href=javascript:history.go(-1)>go back</a> and fill in the <b>EMAIL.</B>"; exit(); }
    if (!$transportation) { echo "Please <a href=javascript:history.go(-1)>go back</a> and fill in the <b>TRANSPORTATION.</B>"; exit(); }

    if (!$timeoutdoors) { echo "Please <a href=javascript:history.go(-1)>go back</a> and fill in the <b>TIMEOUTDOORS.</B>"; exit(); }
    if (!$visit) { echo "Please <a href=javascript:history.go(-1)>go back</a> and fill in the <b>VISIT.</B>"; exit(); }
    if (!$important) { echo "Please <a href=javascript:history.go(-1)>go back</a> and fill in the <b>IMPORTANT.</B>"; exit(); }


    // ENTER THE INFORMATION IN THE DATABASE
    $date=date("m-d-Y");
    $appid=time();
    $sql="INSERT INTO registration (appid, date, name, nadults, nchildren, adultages, childages, contact, address, city, state, zip, phone, email, transportation, ethnicity, ethnicityother, timeoutdoors, visit, important) VALUES ('$appid', '$date', '$name', '$nadults', '$nchildren',
    '$adultages', '$childages', '$contact', '$address', '$city', '$state', '$zip', '$phone', '$email','$transportation','$ethnicity','$ethnicityother','$timeoutdoors','$visit','$important')";
    $result=mysql_query($sql);



    // SEND AN EMAIL NOTIFICATION
    $from="$email";
    $fromname="$name";
    $to="";
    $subject="Lincoln Safari Registration";
    $html="

    <strong>Application ID:</strong> $appid<p>
    <strong>Date:</strong> $date<p>
    <strong>Applicants Name:</strong> $fname $lname<p>
    <strong>Organization:</strong> $organization<p>
    <strong>Nickname:</strong> $nickname<p>
    <strong>Address:</strong> $baddress<p>
    <strong>City, State Zip:</strong> $bcity, $bstate $bzip<p>
    <strong>Telephone:</strong> $phone<p>

    <strong>Email:</strong> $email<p>
    <hr>
    <strong>First Time Attendee:</strong> $attended<p>
    <hr>
    <strong>Total Amount Charged:</strong> $answer<p>
    <strong>Credit Card Type:</strong> $cctype<p>
    <strong>Credit Card Number:</strong> $ccnumber<p>
    <strong>Credit Card Expiration:</strong> $ccexpm/$ccexpy<p>
    <strong>Billing Address:</strong> $ccaddress<p>
    <strong>Billing City, State Zip:</strong> $cccity, $ccstate $cczip<p>
    <strong>Name on Card:</strong> $ccname<p>";
    $text=ereg_replace("<br>","\r\n",$html);
    $attm=array();
    SendMail($from,$fromname,$to,$subject, $html,$text,$attm,"\r\n\r\n");

    // SEND APPLICANT TO SUCCESSFUL PAGE
    header ("Location:successful.php");
    exit();
    }
    ?>




    And here is what is in function.php



    function SendMail($From,$FromName,$To,$Subject,$Text,$Html,$AttmFiles)
    {
    //sends email with attachments
    $OB="----=_OuterBoundary_000";
    $IB="----=_InnerBoundery_001";
    $Html=$Html?$Htmlreg_replace("/\n/","{br}",$Text) or die("neither text nor h
    tml part present.");
    $Text=$Text?$Text:"Sorry, but you need an html mailer to read this mail.";
    $From or die("sender address missing");
    $To or die("recipient address missing");

    $headers ="MIME-Version: 1.0\r\n";
    $headers.="From: ".$FromName." <".$From.">\n";
    $headers.="To: ".$ToName." <".$To.">\n";
    $headers.="Cc: " ."\n";
    $headers.="Reply-To: ".$FromName." <".$From.">\n";
    $headers.="X-Priority: 1\n";
    $headers.="X-MSMail-Priority: High\n";
    $headers.="X-Mailer: My PHP Mailer\n";
    $headers.="Content-Type: multipart/text;\n\tboundary=\"".$OB."\"\n";

    //Messages start with text/html alternatives in OB
    $Msg ="This is a multi-part message in MIME format.\n";
    $Msg.="\n--".$OB."\n";
    $Msg.="Content-Type: multipart/alternative;\n\tboundary=\"".$IB."\"\n\n";

    //plaintext section
    $Msg.="\n--".$IB."\n";
    $Msg.="Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
    $Msg.="Content-Transfer-Encoding: quoted-printable\n\n";
    // plaintext goes here
    $Msg.=$Text."\n\n";

    // html section
    $Msg.="\n--".$IB."\n";
    $Msg.="Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n";
    $Msg.="Content-Transfer-Encoding: base64\n\n";
    // html goes here
    $Msg.=chunk_split(base64_encode($Html))."\n\n";

    // end of IB
    $Msg.="\n--".$IB."--\n";

    // attachments
    if($AttmFiles)
    {
    foreach($AttmFiles as $AttmFile)
    {
    $patharray = explode ("/", $AttmFile);
    $FileName=$patharray[count($patharray)-1];
    $Msg.= "\n--".$OB."\n";
    $Msg.="Content-Type: application/octetstream;\n\tname=\"".$FileName."\"\n"
    ;
    $Msg.="Content-Transfer-Encoding: base64\n";
    $Msg.="Content-Disposition: attachment;\n\tfilename=\"".$FileName."\"\n\n"
    ;

    //file goes here
    $fd=fopen ($AttmFile, "r");
    $FileContent=fread($fd,filesize($AttmFile));
    fclose ($fd);
    $FileContent=chunk_split(base64_encode($FileContent));
    $Msg.=$FileContent;
    $Msg.="\n\n";
    }
    }

    //message ends
    $Msg.="\n--".$OB."--\n";
    mail($To,$Subject,$Msg,$headers);
    //syslog(LOG_INFO,"Mail: Message sent to $ToName <$To>");

    }
    ?>

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    I would probably set up the informtion you want to show in a session? eg:

    at the top of register.php, add

    session_start();

    then in the code

    // SEND APPLICANT TO SUCCESSFUL PAGE
    header ("Location:successful.php");
    exit();

    change to

    PHP Code:
    // SEND APPLICANT TO SUCCESSFUL PAGE
    $_SESSION['name'] = $name;
    $_SESSION['name'] = $contact//etc
    header ("Location:successful.php");
    exit(); 
    then on successful.php you add session_start() at the top and just display what you want.

    Name: <?php echo $_SESSION['name']; ?><br />

    There may be other ways, but that's probably what I would do...

  • Users who have thanked homerUK for this post:

    t-buck (11-29-2007)

  • #3
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Either store it in a session, or forward to a URL like this (might be a bit ugly):

    Code:
    result.php?value1=sometext&value2=somemoretext

  • #4
    New Coder
    Join Date
    Sep 2007
    Posts
    59
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Ok I added the code and then in successful.php this is the file:

    <?php
    session_start();

    Name: <?php echo $_SESSION['name']; ?>

    But I'm getting this error:

    Parse error: parse error, unexpected ':' in /usr/local/apache/htdocs/www.lincolnsafari.org/Registration/successful.php on line 6

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    You didn't close your first PHP tag before you put a plaintext string(Name:).

  • #6
    New Coder
    Join Date
    Sep 2007
    Posts
    59
    Thanks
    7
    Thanked 0 Times in 0 Posts
    so the whole file should look like this:

    <?php session_start(); ?>

    Name: <?php echo $_SESSION['name']; ?>

    Because that gives me this error:
    Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /usr/local/apache/htdocs/www.lincolnsafari.org/Registration/successful.php:3) in /usr/local/apache/htdocs/www.lincolnsafari.org/Registration/successful.php on line 4

  • #7
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    http://www.google.com/search?q=Canno...s+already+sent

    "Results 1 - 10 of about 1,260,000"

  • Users who have thanked aedrin for this post:

    t-buck (11-29-2007)

  • #8
    New Coder
    Join Date
    Sep 2007
    Posts
    59
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Oh see I didn't know that. That's how dumb I am.

    But the google posting helped, and it's now working correctly!

    One last question, is there a way to assign a number to each form submitted, and have it be passed to the output as well? I need the number to start at 2,000 and just increment by one, for each submission.

    For example, the first form submitted would have output of 2,000, and the second would have 2,001. How could I do this?

  • #9
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    PHP Code:
    <input type="hidden" name="number" value="<?php echo !empty($_POST['number']) ? ++$_POST['number'] : 2000?>" />
    Last edited by Inigoesdr; 11-29-2007 at 04:28 PM. Reason: Meant to pre-increment, not post

  • #10
    New Coder
    Join Date
    Sep 2007
    Posts
    59
    Thanks
    7
    Thanked 0 Times in 0 Posts
    So would I put this in the form itself? And then in the register.php add
    $_SESSION['number'] = $number;

    And then do the output in the successful.php

  • #11
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    what you could also do instead of sessions is just query the database and return it from there on successful.php

  • #12
    New Coder
    Join Date
    Sep 2007
    Posts
    59
    Thanks
    7
    Thanked 0 Times in 0 Posts
    you mean for the number 2000? That would be awesome, but I have no idea how to do that. I have the table where the form is being dumped into, set to increment from 2000. So the number is assigned in the database as id. But how do I get that number for the form that was just submitted. No clue.

    I would think that this would work too:
    <input type="hidden" name="number" value="<?php echo !empty($_POST['number']) ? ++$_POST['number'] : 2000; ?>" />

    But I can't get it to display on the output..... I just get the word "number" not an actual number.
    Last edited by t-buck; 11-29-2007 at 04:57 PM.

  • #13
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    I have the table where the form is being dumped into, set to increment from 2000. So the number is assigned in the database as id. But how do I get that number for the form that was just submitted. No clue.
    PHP Code:
    $generatedId mysql_insert_id(); 
    mysql_insert_id

  • #14
    New Coder
    Join Date
    Sep 2007
    Posts
    59
    Thanks
    7
    Thanked 0 Times in 0 Posts
    ok so I added this to register.php
    $generatedId = mysql_insert_id();

    and then at the bottom of that file:
    $_SESSION['number'] = $generatedId;

    And then in successful.php
    Group Number: <?php echo $_SESSION['number']; ?> <br />

    But the number outputted is "0" every time. Do I have this set up wrong? Is the id not assigned till after register.php has run? So do I need to somehow call the number from successful.php

  • #15
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You want to make sure each step is working. Try adding die("generatedId is $generatedId"); just after you assign a value to that variable to see if that is working. If it is, move on to the next step and add a similar statement right after you assign your session variable.

    You could show us your code again... you should use the [ PHP ] tags this time though. It does seem like you're on the right track.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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