Results 1 to 2 of 2

Thread: Hrm.. So PHP Is Your Wanted Fetish eh..

  1. #1
    er0k
    Guest

    Hrm.. So PHP Is Your Wanted Fetish eh..

    Well, basically I helped someone out alot tonight getting them started on php, etc.. then running them through their first scripts.. So I will paste these scripts and explain what each one does, why it does it, etc.. I know there are much better php programmers on AO than myself, but this is intended for people that:

    [a] have php installed
    [b] have some sort of webserver running or
    have access to a webserver to add files or just
    basic scripts to that allow .php, .php3 or something
    file extensions..
    [c] are interested in getting started with PHP without
    having to read an entire book.

    Ok, PHP Is another object oriented programming language that was developed mainly by a guy named Rasmus Lerdorf. The guy ownz

    Along the way, if you encounter any troubles, check out www.php.net/manual/en for people that wish to read it in english, or www.php.net/manual to select a language.
    ( i might want to add that im a bit tipsy.. so bear with me..)


    First off, i will show you all a script that prints out something:
    Code:
    <?
    
    echo "Hello my name is er0k";
    
    ?>
    ^^ will print to the browser "Hello my name is er0k" <- without the quotation marks.

    As many of you have noticed... wow that looks like an easy thing to do..

    Well, php is much more extensive and much more powerful/difficult than what you first perceive, or at least in this short tutorial. So remember that, and hang at www.phpbuilder.com, www.pastebin.com, or if you want in depth discussion, www.bytekill.net
    <- not advertising we just have a handful of php programmers who hang around.



    Code:
    <html>
    <head><title>Some title</title></head>
    <body bgcolor=black>
    <font face=verdana size=1 color=white>
    <body>
    
    
    
    
    
    <form action="<? $PHP_SELF ;?>" method="post">
    <input type="text" name="number1">
    <input type="submit" name="submitno1">
    
    <form action="<? $PHP_SELF ;?>" method="post">
    <input type="text" name="number2">
    
    
    
    <?
    
    $number1 = $_POST['number1'];
    $number2 = $_POST['number2'];
    echo "Enter 2 numbers to be added together once the page processes.";
    
    
    
    if($number1 && $number2)
    
    {
    
    echo "Numbers added together : ";
    echo $number1 + $number2;
    
    }
    Ok, what this page does, is first off, gets two different numbers from someone in a text field, and then adds them together.. a pretty simple script... eh?

    But how does it work?


    Well, the Html, ie things that aren't inside the <? ?> tags, dont really effect the php that much at all, in fact hardly ever. Except of course with more complex forms and specific built in html functions, etc.. but we wont get into that..

    Alright, so what does each bit of this thingy here do?

    Well, first off, it starts out with a form, which gets the desired information, processes it, and then displays it with the post method..

    Then, moving on.. begins to decided whether or not the information was properly provided. This script however, does not have special functions or anything at all to prevent numbers only to be inputted, it was just a simple thing i whipped out for this tutorial to get some of you to realize how to start off with web programming.

    The:

    [code]

    if($number1 && $number2) function basically just checks to see that the user actually did anything at all, if not it returns null and does nothing, ie doesn't output anything.


    What this script here essentially does is:

    1. get the users two numbers

    2. decide if they can be added or not, or rather, if the fields are filled out in some way (if you just put a space in it prints 0 for the total..)

    3. adds them together and displays it..


    When im more in the mood ill write something much more descriptive for php programmers, but right now i think this is basic enough for you all to manipulate the code, and figure out how these specific functions/variables/syntax work, and what you can do with them.

    Have fun, ill write part 2 with much more detail coming very soon, im tired however and dont want to just continually add stuff to this, so as to make room for part 2, so you all can read it in parts rather than sit there for hours upon hours.. god i hate tutorials that are too long..



    php ownzers..

  2. #2
    Junior Member
    Join Date
    Jul 2003
    Posts
    2
    Excellent. :woot: PHP is something that I have really been needing to get into. I co-own a site that utilizes a PHP based chat forum and I'd really like to get to know my way around the code. Thanks for the links.
    What people see as truth is often collective speculation.

    - Grey

Posting Permissions

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