Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Learning PHP

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2009
    Posts
    76,596

    Default Learning PHP

    Example Script to display Date

    Code:
     <html>
    
    <head>
    <title>Example #3 TDavid's Very First PHP Script ever!</title>
    </head>
    <? print(Date("m/j/y")); ?>
    
    <body>
    </body>
    </html>

    You can view the result at : http://198.27.105.229/example_test001.php
    Last edited by sherlyk; 05-06-2014 at 07:08 AM.

  2. #2
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    change background color based on day of the week

    Code:
    <html>
    <head>
    <title>Background Colors change based on the day of the week</title>
    </head>
    <? 
    $today = date("l");
    print("$today");
    if($today == "Sunday") 
    {
    $bgcolor = "#FEF0C5";
    }
    elseif($today == "Monday")
    {
    $bgcolor = "#FFFFFF";
    } 
    elseif($today == "Tuesday") 
    {
    $bgcolor = "#FBFFC4";
    } 
    elseif($today == "Wednesday")
    {
    $bgcolor = "#FFE0DD";
    } 
    elseif($today == "Thursday")
    {
    $bgcolor = "#E6EDFF";
    } 
    elseif($today == "Friday") 
    {
    $bgcolor = "#E9FFE6";
    } 
    else 
    {
    // Since it is not any of the days above it must be Saturday
    $bgcolor = "#F0F4F1";
    }
    print("<body bgcolor=\"$bgcolor\">\n"); 
    ?>
    <br>This just changes the color of the screen based on the day of the week
    </body>
    </html>
    You can view the result at : http://198.27.105.229/example_test002.php

  3. #3
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    Syntax to display Date

    Code:
    <html>
    <body>
    
    <h1>My first PHP page</h1>
    
    <?php
    echo "Hello World!";
    ?>
    
    </body>
    </html>
    You can view the result at : http://198.27.105.229/example_test003.php

  4. #4
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    PHP Forms

    Code:
    <html>
    <body>
     
    Hello <?php echo $_POST["firstName"]; ?>, your email,
    <?php echo $_POST["email"]; ?>, has now been added.
     
    </body>
    </html>
    You can view the result at : http://198.27.105.229/example_test004.php

  5. #5
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by sherlyk View Post
    PHP Forms

    Code:
    <html>
    <body>
     
    Hello <?php echo $_POST["firstName"]; ?>, your email,
    <?php echo $_POST["email"]; ?>, has now been added.
     
    </body>
    </html>
    You can view the result at : http://198.27.105.229/example_test004.php

    For this to work, you need a HTML form page like

    Code:
    <html>
    <body>
    
    <form action="example_test004.php" method="post">
    
    <div>
    Enter your name: <input type="text" name="firstName">
    </div>
    
    <div>
    Email: <input type="text" name="email">
    </div>
    
    <button type="submit">Add Me</button>
    
    </form>
    
    </body>
    </html>

    Save it as

    example_test004.html
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  6. #6
    Join Date
    Sep 2003
    Posts
    3,040

    Default

    Quote Originally Posted by sherlyk View Post
    PHP Forms

    Code:
    <html>
    <body>
     
    Hello <?php echo $_POST["firstName"]; ?>, your email,
    <?php echo $_POST["email"]; ?>, has now been added.
     
    </body>
    </html>
    You can view the result at : http://198.27.105.229/example_test004.php

    For this to work, you need a HTML form page like

    Code:
    <html>
    <body>
    
    <form action="example_test004.php" method="post">
    
    <div>
    Enter your name: <input type="text" name="firstName">
    </div>
    
    <div>
    Email: <input type="text" name="email">
    </div>
    
    <button type="submit">Add Me</button>
    
    </form>
    
    </body>
    </html>

    Save it as

    example_test004.html
    Become PHP Expert in 30 days
    FreeMarriage.com - Free Online Matrimonial
    FlashWebHost.com - Professional Web Hosting, Designing.

  7. #7
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    Introductory programming and scripting tutorials, our first example will print "Hello World"

    Code:
    <HTML>
    <HEAD>
    <TITLE> Hello World in PHP </TITLE>
    </HEAD>
    <BODY>
    <?
    // Hello world in PHP
     print("Hello World");
    ?>
    </BODY>
    </HTML>

    You can view the result at : http://198.27.105.229/example_test007.php

    This is same as

    http://forums.bizhat.com/showthread.php/134951

  8. #8
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    PHP Uploading Files

    upload.html

    Code:
    <html>
    <head>
    <title>File Upload Form</title>
    </head>
    <body>
    This form allows you to upload a file to the server.<br>
    
    <form action="upload.php" method="post"><br>
    Type (or select) Filename: <input type="file" name="uploadFile">
    <input type="submit" value="Upload File">
    </form>
    
    </body>
    </html>
    Save following as

    upload.php

    Code:
    <html>
    <head>
    <title>Process Uploaded File</title>
    </head>
    <body>
    <?php
    
    move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
           "./uploads/{$_FILES['uploadFile'] ['name']}")
    
    ?>
    </body>
    </html>
    Create a directory "uploads" in current folder.

    Note: This script is insecure. Do not upload to public server and keep it there. Anyone can upload files to your web server. For example, they upload a movie or a PHP Shell (hacked tool) or spam mail too and sent mail. There can be lot of abuse if such a script is made available on a public server.

  9. #9
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    Script to display Date

    Code:
    <html>
    <head>
    <title>Page last updated on month/date/year hour:min PHP Script</title>
    </head>
    <?
    $last_modified = filemtime;
    print("Last Modified ");
    print(date("m/j/y h:i", $last_modified));
    ?>
    </body>
    </html>
    You can view the result at : http://198.27.105.229/example_test005.php

  10. #10
    Join Date
    Nov 2009
    Posts
    76,596

    Default

    Easy to learn PHP, it shows both the PHP source code and the HTML output of the code.

    Code:
    <html>
    <body>
    
    <?php
    echo "My first PHP script!";
    ?>
        
    </body>
    </html>
    You can view the result at : http://198.27.105.229/example_test006.php

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

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