www.webdeveloper.com
Results 1 to 9 of 9

Thread: Can't get the most simple PHP example to work...

  1. #1
    Join Date
    Aug 2012
    Posts
    2

    Unhappy Can't get the most simple PHP example to work...

    I am new to PHP and learning it using examples and online tutorials.
    My goal is to use an HTML form (with a 'Submit' button) for collecting inputs from the user and then using PHP to collect the inputs and process them on the server.
    I have tried several examples that were available online, but couldn't get any of them to work on my computer.
    This example is supposed to collect an input and simply echo it back.

    The HTML code:
    <html><body>
    <h4>Tizag Art Supply Order Form</h4>
    <form action="process.php" method="post">
    <select name="item">
    <option>Paint</option>
    <option>Brushes</option>
    <option>Erasers</option>
    </select>
    Quantity: <input name="quantity" type="text" />
    <input type="submit" />
    </form>
    </body></html>


    The PHP code (file saved as "process.php"):
    <html><body>
    <?php
    $quantity = $_POST['quantity'];
    $item = $_POST['item'];
    echo "You ordered ". $quantity . " " . $item . ".<br />";
    echo "Thank you for ordering from Tizag Art Supplies!";
    ?>
    </body></html>


    The output (in Chrome):
    "; echo "Thank you for ordering from Tizag Art Supplies!"; ?>

    Thanks in advance for your support!

  2. #2
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    Hi, and welcome to the forum.

    Did you install PHP on your computer?

    If so, maybe you're saving your files in the wrong folder? I seem to remember, back when I was running PHP on my computer, that my files would only run if I saved them in the right directory. I was using Xampp (some thingy that comes with PHP, a web server, and other stuff) so it was c:\\xampp\htdocs\xampp

    I try to help people here but I'm not that good at it yet. If I have failed to be of any assistance, fear not, somebody much more experienced than me will reply :P
    Last edited by evenstar7139; 08-20-2012 at 12:46 AM.

  3. #3
    Join Date
    Aug 2012
    Posts
    2

    Isn't it part of Expression Web

    Thanks Evenstar for your reply.
    I have Microsoft Expression Web recent version installed, although those program files were not created using it.
    Do i still need to install PHP?
    By the way, the two program files are located at the same folder.

    Thanks for your help.

  4. #4
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,114
    I just answered this for someone on the previous thread...

    http://www.webdeveloper.com/forum/sh...d.php?t=263708


    There are 4 examples laid out for you to demonstrate it in PHP and Javascript. All are working.

  5. #5
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,114
    PHP Code:
    <h2>Enter your text in the form</h2>
    <form name="form1" method="post" action="">
    <input type="text" name="something" size="36" /> &nbsp;&larr; Enter some short text here.<br />
    <textarea rows="3" cols="55" name="text"></textarea> &nbsp;&larr; Enter long text here.<br />
    <input type="submit" value="Go" />
    </form>
    <div id="mydiv" name="mydiv">
    <?php

    // The lines below capture the data sent from the form
    $something $_POST['something'];
    $text $_POST['text'];

    // The next lines (below) return some text if the forms are both empty
    if(empty($something) && empty($text)) {
    echo 
    'XXXXXXXXX - This is some text - XXXXXXXXXXXXX';
    } else {

    // The lines below use "HEREDOC" to simply output whatever was typed into the forms
    echo <<<EOD
    <b>$something</b><br /> $text
    EOD;
    }

    ?>
    </div>

  6. #6
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,114
    form.html
    HTML Code:
    <html><body>
    <h4>Tizag Art Supply Order Form</h4>
    <form action="process.php" method="post"> 
    <select name="item"> 
    <option>Paint</option>
    <option>Brushes</option>
    <option>Erasers</option>
    </select>
    Quantity: <input name="quantity" type="text" /> 
    <input type="submit" />
    </form>
    </body>
    </html>
    File: process.php
    PHP Code:

    <html>
    <body>
    <?php
    $quantity 
    $_POST['quantity'];
    $item $_POST['item'];
    echo 
    "You ordered $quantity $item <br />";
    echo 
    'Thank you for ordering from Tizag Art Supplies!';
    ?>
    </body>
    </html>

  7. #7
    Join Date
    Aug 2006
    Posts
    1,942
    Quote Originally Posted by simtom View Post
    Thanks Evenstar for your reply.
    I have Microsoft Expression Web recent version installed, although those program files were not created using it.
    Expression Web does not come with PHP, so if you're trying to run these on your local computer, you do need PHP installed.

    Dave

  8. #8
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    You might consider installing XAMPP or WAMP on your system. They provide support for apache web server, mysql, and php. Both are free. You can still use your MS program to make pages with.

    Also local web pages must be opened as a url such as //localhost/index.php and not as a file i.e. file://c:/somepath/index.php.

  9. #9
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    Wow so I was right about the possibility of simtom not having PHP installed? Yay! I feel useful now.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles