+ Reply to Thread
Page 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: New to PHP and very confused...

  1. #1
    bpakidz's Avatar
    bpakidz is offline x10Hosting Member bpakidz is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Paradise -- yeh, right!
    Posts
    36

    New to PHP and very confused...

    Okay, so I was trying to get a form to send the results to me via email. Someone else had the same issue and was told that a php script would solve the issue. Fine, great... but I don't get how to use it in my situation. I wrote a script and called it HandleForm.php my trusty, dusty PHP book (Visual Quickstart Guide - PHP for the World Wide Web) shows how to do this. I uploaded the page with the form and the corrected action as well as the php page. But now... it doesn't work. I was getting the php page with no input but now, I get nothing.

    I saw elsewhere where a member talked about phpMyAdmin. I went there on the cPanel, but it's all greek to me. Where can I get help with php and this phpMyAdmin application?

    This is what I wrote. Can there only be one string/variable on a line? Is that part of my problem?

    PHP Code:
    <HTML>
    <HEAD>
    <TITLE>Form Resluts Page</TITLE>
    <BODY leftmargin="10%" rightmargin="20%" bottommargin="25">
    <?php 
    /* This page handles the received data from the form "bpaforms.html". */
    print "Thank you for submitting your information, $First.<BR>\n";
    print 
    "We show your address as $Address \n";
    print 
    "in $City$State $ZIP.<br>\n";
    print 
    "Your phone number is $phone \n";
    print 
    "and your e-mail address is $email.<BR>\n";
    print 
    "You have asked us to send you information about our schools for your child(ren),<BR>
    $Child1, age $Age1 ($Sex1),  $Child2, age $Age2 ($Sex2),  $Child3, age $Age3 ($Sex3)<BR>\n";
    ?>
    </BODY>
    </HTML>
    To see it in action (or not), the page is here.
    Last edited by bpakidz; 09-01-2008 at 03:35 PM.

  2. #2
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: New to PHP and very confused...

    PHP Code:
    <HTML>
    <HEAD>
    <TITLE>Form Resluts Page</TITLE>
    <BODY leftmargin="10%" rightmargin="20%" bottommargin="25">
    <?php 
    /* This page handles the received data from the form "bpaforms.html". */
    $First $_POST['First'];
    $Last $_POST['Last'];
    $Address $_POST['Address'];
    $City $_POST['city'];
    $State $_POST['State'];
    $ZIP $_POST['ZIP'];
    $phone $_POST['phone'];
    $email $_POST['email'];
    $Child1 $_POST['Child1'];
    $Age1 $_POST['Age1'];
    $Sex1 $_POST['Sex1'];
    $Child2 $_POST['Child2'];
    $Age2 $_POST['Age2'];
    $Sex2 $_POST['Sex2'];
    $Child3 $_POST['Child3'];
    $Age3 $_POST['Age3'];
    $Sex3 $_POST['Sex3'];

    print 
    "Thank you for submitting your information, $First.<BR>\n";
    print 
    "We show your address as $Address \n";
    print 
    "in $City$State $ZIP.<br>\n";
    print 
    "Your phone number is $phone \n";
    print 
    "and your e-mail address is $email.<BR>\n";
    print 
    "You have asked us to send you information about our schools for your child(ren),<BR>
    $Child1, age $Age1 ($Sex1),  $Child2, age $Age2 ($Sex2),  $Child3, age $Age3 ($Sex3)<BR>\n";
    ?>
    </BODY>
    </HTML>
    depending on your form, whether the method says post or get, you would use global varialbes to get data from it.

    if it's post, you'll do $_POST['input_name'] to get the data from the input field named input_name.

    if you used $_GET['act'], you'll get data from the url, so index.php?act=blah&p=2 would make $_GET['act']'s value "blah" and $_GET['p'] equal to "2".

    You can echo/print multiple variabes in one line. Above, what you did as far as variables is right, I just don't think you retrieved any information from the previous field.

    -xP
    Last edited by xPlozion; 09-01-2008 at 03:53 PM.

  3. #3
    marshian's Avatar
    marshian is offline x10 Elder marshian is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: New to PHP and very confused...

    I can't remember which setting did this, but there's a setting in php which makes all post/get data a global variable. This is a large security risk. That's why you should always disable that setting!
    This is also why your script is not working.
    As xP already pointed out, you could use $_GET or $_POST (depending on your form method). I just wanted to explain a little why you/your php book failes there, and also mention $_REQUEST, which is $_GET and $_POST (and $_COOKIE) at the same time. But it's better to use the specific global instead of request, if you already know which one you should use.

    - Marshian
    Real programmers don't document their code - if it was hard to write, it should be hard to understand.

  4. #4
    bpakidz's Avatar
    bpakidz is offline x10Hosting Member bpakidz is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Paradise -- yeh, right!
    Posts
    36

    Re: New to PHP and very confused...

    Awesome! Thank you so much!! I couldn't understand how the script could be as small as I had it and still work. I had a feeling I was missing something major. Thanks for pointing it out and for the information. Hopefully it will help in the long run.


    Also, how would I use this to send an email? I'd only need to change the action, right?

  5. #5
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: New to PHP and very confused...

    np, always here to help

    Register globals is a HUGE security risk as mentioned above, which is why it's no longer On by default.
    PHP Code:
    <?php
    if ($a==1$username="Henry";
    $res mysql_query("SELECT uid, password FROM user WHERE username='$username'");
    ?>
    with registered globals on, if the url is
    ?a=2&username=' OR ''=''
    then that'll transform the query into
    "SELECT uid, password FROM user WHERE username='' OR ''=''
    and since '' == '', then it'll return all usernames and all passwords
    Last edited by xPlozion; 09-01-2008 at 05:03 PM.

  6. #6
    woiwky is offline x10 Lieutenant woiwky is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    390

    Re: New to PHP and very confused...

    Just a note, Register Globals isn't as big of a security risk as is commonly said. If you code with security in mind (as you should), you probably wouldn't run into any issues with it. However, since it promotes bad habits and can be misused by beginners, it's generally not a good idea to enable it.
    "But you have access to the greatest source of knowledge in the universe."
    "Well I do talk to myself sometimes, yes."

    "I'm back, and I'm bad! Obviously within certain, sensible, preset parameters"

  7. #7
    bpakidz's Avatar
    bpakidz is offline x10Hosting Member bpakidz is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Paradise -- yeh, right!
    Posts
    36

    Re: New to PHP and very confused...

    Quote Originally Posted by woiwky View Post
    Just a note, Register Globals isn't as big of a security risk as is commonly said. If you code with security in mind (as you should), you probably wouldn't run into any issues with it. However, since it promotes bad habits and can be misused by beginners, it's generally not a good idea to enable it.
    Thanks... I still don't understand what it is, so there's no worry of enabling it. :dunno:
    -- Karen
    :rant2:Designing, Learning, Coding and going crazy!

    Whatever happens, take responsibility
    -- Tony Robbins

  8. #8
    marshian's Avatar
    marshian is offline x10 Elder marshian is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: New to PHP and very confused...

    Say you got a query part of an url ?var1=value , you can access variable var1 as $_GET["var1"]. If you have Register Globals on, you can also access it as $var1 .
    Last edited by marshian; 09-02-2008 at 03:20 PM.
    Real programmers don't document their code - if it was hard to write, it should be hard to understand.

  9. #9
    bpakidz's Avatar
    bpakidz is offline x10Hosting Member bpakidz is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Paradise -- yeh, right!
    Posts
    36

    Re: New to PHP and very confused...

    OKay, y'all... I think this issue is resolved! Thanks SO very much for all the help. I am off to play in the land of php and see what else I can find.



    Please CLOSE this thread. Thanks!
    -- Karen
    :rant2:Designing, Learning, Coding and going crazy!

    Whatever happens, take responsibility
    -- Tony Robbins

  10. #10
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: New to PHP and very confused...

    Glad you got it working and learned from here.

    You can close your own topics in this section (when you post, towards the bottom of the page, there's a checkbox to close the topic). Also, please give credit where due (as rep) ;)

    Until next time,
    -xP

+ Reply to Thread
Page 1 of 3 123 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
x10hosting free hosting for the masses
dedicated servers