#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0

    PHP Form question


    OK..... So. I am not exactly a programmer by any means. I am a Network Admin who specializes in servers n stuff, not programming. Sadly my Director wants me to build the new company intranet site. I have been making pretty good strides and I am comfortable enough with HTML and CSS to get around. I am learning PHP now to make something better. I have an IIS 7 server setup and an apache server, which is personal host (for testing mainly).

    Right now I am trying to do some proof of concept testing with forms. I have read most everything I can find and all of my code and HTML looks right to me, but obviously I highly doubt its right. I cannot get my PHP form to output the data to the echo statement. The data disappears from the input boxes, then does nothing.

    Here is the basic HTML I have :

    Code:
    <html>
    <body>
    <form = " Office Supply Order Form" action "Office_supply.php" Method="post">
    	Requestor Name and Extention:<input name="Requestor" id="Requestor" type="text" /><br />
    	Site: <input name="Site" id="Site" type="text" /><br />
    	Department: <input name="Dept" id="Dept" type="text" /><br />
    	"Grant Used (If any)" <input name="Grant" id="Grant" type="text" /><br />
    	AAA Batteries	Item Number 479074  4/pk  $3.41 Each. QTY:<input name="AAABattery" id="AAABattery" type="text" size="4" /></br>
    	AA Batteries    Item Number 479067  4/pk  $2.09 Each. QTY:<input name="AABattery" id="AABattery" type="text" size="4" /></br> 
    	Tissue			Item Number 21606	Box	  $0.84	Each. QTY:<input name="Tissue" id="Tissue" type="text" size="4" /></br>
    <input type="Submit" value="Submit" />
    </form>
    
    </body>
    </html>
    Here is the PHP:

    PHP Code:
    <?php
    $Requestor 
    $_POST['Requestor'];
    $Site $_POST['Site'];
    $Dept $_POST['Dept'];
    $AAABattery $_POST['AAABattery'];
    $AABattery $_POST['AABattery'];
    $Tissue $_POST['Tissue'};
    ?>

    <?php
    echo ""$Requestor" Ordered "$AAABattery" AAA Batteries, "$AABattery" AA Batteries, and ."$Tissue" Tissues for the "$Dept" department at "$Site"" ;
    ?>
    any insight or advice would be excellent, or even some recommendations on a web tutorial, or book for those that don't program to learn php
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,129
    Rep Power
    9398
    The only thing wrong with the form is the opening <form> tag. It's quite... uh... not right. Try
    Code:
    <form action="Office_supply.php" method="post">
    Not sure what the "Office Supply Order Form" is supposed to be.

    For the PHP it's a good start but the way you put "s into the string isn't correct. Because the string itself uses "s as delimiters. Escape the ones inside with a backslash.
    PHP Code:
    echo "\"$Requestor\" Ordered \"$AAABattery\" AAA Batteries, ..."
    In case you thought it, those quotes inside aren't necessary to display variables. You're literally going to get
    Code:
    "Bob" Ordered "2" AAA Batteries, ...
    output.

    Comments on this post

    • ManiacDan agrees : Maybe he "wants" it like "that"
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0
    I dont really care how it looks right now :P just a proof of concept to show myself I can do it. I'll make it look better later.

    I changed the form tags in the HTML and escaped the "

    Know it gives me a 404 error when it cant find the .php file. I think this is a good sign! At least I can see the form is trying to locate the php file now

    After correcting the path to the right file it still doesn't work. Does the .php file need the html tags in it to properly display, or just the base .php file with the php tags and code? Here is the entirety of what the php file is currently:

    PHP Code:
    <?php
    $Requestor 
    $_POST['Requestor'];
    $Site $_POST['Site'];
    $Dept $_POST['Dept'];
    $AAABattery $_POST['AAABattery'];
    $AABattery $_POST['AABattery'];
    $Tissue $_POST['Tissue'};
    ?>

    <?php
    echo "\"$Requestor\" Ordered \"$AAABattery\" AAA Batteries, \"$AABattery\" AA Batteries, and \"$Tissue\" Tissues for the \"$Dept\" department at \"$Site\"" ;
    ?>
  6. #4
  7. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    hello SirSpectre,
    $Tissue = $_POST['Tissue'};
    should be
    $Tissue = $_POST['Tissue'];

    Comments on this post

    • SirSpectre agrees : Eagle eye !
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0
    Good eye! Fixed!

    I did some screwing around with html tags inside the php file and that still returns no results. I think I am going to go back and read up much more from a few more sources to see what I'm doing wrong.
  10. #6
  11. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    What do you mean "returns no results"?
    If you mean that instead of displaying the content of, say, "$_POST['Tissue'];" nothing shows?

    You have to becareful because $_POST['Tissue'] and $_POST['tissue'] are different. Check what your fields are called in your form and I also recommend that before you assign the variables, add this line --> print_r($_POST); under the <?php line and it'll write to screen the content of the POST data, you might either get Array() (which means there is none) or see what values are in the $_POST array.

    Oh and as far as eagle-eye goes, lol cheers!
    Last edited by badger_fruit; October 27th, 2012 at 04:21 PM. Reason: clarification
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0
    Added the line and here is the array that showed up:

    Array ( [Requestor] => asdf56 [Site] => asdfasdf [Dept] => asdf [Grant] => asdf [AAABattery] => 12 [AABattery] => 3 [Tissue] => 2 ) "asdf56" Ordered "12" AAA Batteries, "3" AA Batteries, and "2" Tissues for the "asdf" department at "asdfasdf"

    No results meant that I actually got a CGI server error when I pressed the submit button.

    Edit: The CGI error was before I added the new print_r line
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    5
    Rep Power
    0
    I figured out it was missing a . between the variables. Now I am just figuring out formatting for the echo statement. This is what I came up with so far to show

    "I Ordered 3 AAA Batteries"

    PHP Code:
    echo $Requestor " ordered " $AAABattery " AAA Batteries "
    This works! I just think there is a better way to get regular text in the statement without having to put the spaces in the quotes, and without having to use the . before and after the variable.

    Any thoughts?
  16. #9
  17. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,129
    Rep Power
    9398
    Nothing that actually matters. Just changes to how the code looks. For now stick with the typical things and wait to branch out into odder things until you're more familiar with PHP.
  18. #10
  19. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    Originally Posted by SirSpectre
    I figured out it was missing a . between the variables. Now I am just figuring out formatting for the echo statement. This is what I came up with so far to show

    "I Ordered 3 AAA Batteries"

    PHP Code:
    echo $Requestor " ordered " $AAABattery " AAA Batteries "
    This works! I just think there is a better way to get regular text in the statement without having to put the spaces in the quotes, and without having to use the . before and after the variable.

    Any thoughts?
    When I am echo'ing variables, I enclose them in curley braces like so:-
    PHP Code:
    echo "{$Requestor} ordered {$AAABattery} AAA Batteries "
    But like requinix says, it's neither here nor there (it just seems to make my life easier rather than having billions of " and . everywhere!
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2008
    Posts
    1,928
    Rep Power
    378
    So, you're not planning on having any back-end database actually managing this stuff?

IMN logo majestic logo threadwatch logo seochat tools logo