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 14 of 14
  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Location
    Guildford, UK
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    where do i program php?

    i am a completely noob at php, i only heard of it this morning

    i have a webpage that uses javascript to use multiple combo boxes and a textarea as part of a form. i need to submit this data to another page and save it in the form of a list. so that it is stored on the page in date order.
    i have been told i need to use PHP to do this.

    my question is how do i program PHP and where do i do it? does it go in my javascript in script editor or do i need another editor? how do i link to it?

    as u can tell i know nothing on this subject so any help would be cool!

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can put PHP anywhere in your page so long as it is in between PHP tags (a little like javascript's <script> tags - PHP tags are <?php code goes in here ?>).

    In order to do what you want to do you will need a separate php script that your form submits to (using the action="" element). You can then access all the named form elements using $_POST. This is a cut-down version of how it would work:

    PHP Code:
    // this is your html form
    <form name="sendmail" method="post" action="mymail.php"> // the name of your script goes in the action field - mymail.php in this case
        <input name="name" type="text" id="name"> name<br />
        <input name="email" type="text" id="email"> email<br />
        <input type="submit" name="Submit" value="Submit">
    </form>

    // mymail.php
    <?php

    $output 
    time() . '<br />'// this creates a timestamp which you can later manipulate to turn into a date
    foreach($_POST as $key => $value) {
        
    $output .= "$key = $value<br />";
    }

    echo 
    $output;

    ?>
    That's a basic example which just echoes all the data back to your browser window. In order to store the data you need to decide how you want this to happen. You could store the information in one file on your server, or in multiple files or you might want to store it in a database (more useful for manipulating the data) or have the information mailed to your email automatically. Which option you go for will determine how your code will need to look.

    The best advice I can give at this point is to google for some basic PHP tutorials and you will soon pick it up, it's not too difficult and what you're asking for is definitely possible.

  • #3
    Regular Coder
    Join Date
    Jul 2005
    Location
    Guildford, UK
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, so the same as having <script></script> i just use php tags withing my script...

    i had a look on php.net, do i need to install anything on my pc? the reason i ask is whenever i paste some code into my script, it all appears black and doesnt do much :S

    thanks for the reply!

  • #4
    Regular Coder
    Join Date
    Jul 2005
    Location
    Guildford, UK
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ooo im so confused, this is what ive got...

    </html>
    </TR>

    </table>
    <?php
    echo 'hello';
    ?>
    <TR>
    <TD VALIGN="BOTTOM">


    as u can see its sat there in the middle of my page, but i cant see anything when i open the page...what am i doing wrong?
    so need to get some books on this i think!!!

  • #5
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You won't be able to view it on your PC unless you install PHP on your home machine. You will need to make sure that your web server supports PHP and you will also need to save your files with a ".php" extension instead of the usual .htm or .html - this tells the server to run the page as a PHP script.

    The easiest way to test if your server supports PHP is to create a page with the following contents:
    PHP Code:
    <?php
    php_info
    ();
    ?>
    Then browse to that page - if your server is PHP-enabled you will see a whole lot of information about the configuration. If you don't have PHP on your server you'll probably just see the code appear as text.

  • #6
    Regular Coder
    Join Date
    Jul 2005
    Location
    Guildford, UK
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts
    man, im showing my complete lack of knowledge here....

    so i type that into a new html page, then save it as *.php, save it to my website, then i go to that page via IE?

    im soooo confused

    EDIT: i have tried this and it loads up a notepad file with the code in it...
    Last edited by theexo51; 07-07-2005 at 01:13 PM.

  • #7
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Double check the extension for the file is .php and not .txt - if it's still not working then it looks like your host doesn't allow PHP, you will need to see if it's something they offer as an extra or find a new host.

    You can still install PHP on your PC and use that to practice writing scripts until you have the hosting situation resolved, but I've never done that so I couldn't tell you how easy it is. I think firepages has some packages that make this easier on his site, there is a sticky about it in the main forum here if you want to take a look.

  • #8
    Regular Coder
    Join Date
    Jul 2005
    Location
    Guildford, UK
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah, i guess its my server thats the issue.

    i could do with getting installed locally tho, its annoying that what im trying to do will only work with php yet i cant get it working!
    ive downloaded some files for php but none seem to have an installer or anything i recognise as being useful. if theres anyone willing to guide me thru this process i would be muchos grateful...

    thanks guys

  • #9
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    If you wanna run webserver software (Apache, PHP etc) on your computer you can either download each item or you can download an apache distro such as XAMPP which installs it all for you

  • #10
    Regular Coder
    Join Date
    Nov 2004
    Location
    The Netherlands
    Posts
    551
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A link to phpdev is right on this forum, phpdev doesn't need to be configured.
    CATdude about IE6: "All your box-model are belong to us"

  • #11
    New Coder
    Join Date
    Apr 2005
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    here's a link to a tutorial to guide you through the installation process, I used this and it worked a treat,
    http://www.webmasterstop.com/48.html
    good luck!
    Steve

  • #12
    Regular Coder
    Join Date
    Jul 2005
    Location
    Guildford, UK
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts
    okay, lets do this RARGHH....*cough*

    well...the website looks handy so giving that a go, hopefully i will get further than i did trying on me own.

    cheers

    EDIT: ok so im looking at this and Apache needs my domain name etc, trouble is i am on a LAN and my boss probly wont want me to do anything on his web server, is there a way to get PHP working on my machine first then put it on the server if he thinks its worth it?
    Last edited by theexo51; 07-07-2005 at 02:46 PM.

  • #13
    Regular Coder
    Join Date
    Jul 2003
    Posts
    262
    Thanks
    1
    Thanked 0 Times in 0 Posts
    If you get the phpdev package from firepages and install it on your machine you'll have everything you need. Basically you have to edit the httpd.conf file in a couple places to tell it where your webroot is on your local machine (where ever your site files are located). There are a couple of batch files that will be on your start menu, you just pick the one that goes with your OS, and run it. That will start Apache and open your homepage in your browser. From there you can view php in action as you develop your site.

    If you plan on uploading this to a webserver or you lan, you need to make sure it is running Apache otherwise it will not serve your pages correctly (just like your machine won't until you have Apache running).

    Just read the getting started docs that come with it and you'll be in good shape.

  • #14
    Regular Coder
    Join Date
    Jul 2005
    Location
    Guildford, UK
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts
    mothra, hey man, thanks, didnt see those bits in the start menu.
    opened it up and hey presto i see the php stuff, now its just a matter of figuring out which string to change in the .conf file to point at the file which has all the website stuff.

    cheers for all the help guys, i feel like im getting somewhere!

    EDIT: i did it, ooo i have a warm fuzzy feeling inside! now the hard bit
    Last edited by theexo51; 07-08-2005 at 09:22 AM.


  •  

    Posting Permissions

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