Cyberiot Home

Budget Hosting

Domain Search

Server Hardware

Free Newsletter

Search Website

FAQ

Support

Set-up Domain

 Contact Us

Recommend this Site

 

Renew Domain

 

PHP4

PHP (officially "PHP: Hypertext Preprocessor") is a server-side HTML-embedded scripting language. Use extension such as .phtml for your HTML files to parse PHP properly.

NavBar- Header - Footer: Make it easy to update all pages

I've been asked many times about navigation and how to update many pages easily using PHP. Because of it's speed in page delivery, simply include sections of your page with a one-line code.

There are many fancy ways to accomplish these things, but we want fast, simple, non-technical ways to deliver web content. 

Display areas that need to be consistent throughout your site, regardless of page visitor is currently viewing. 

  • Header - visible area at the top of page
  • Footer - visible area at the bottom
  • Navbar - Navigation box or bar depending on your layout

First: Create your home page and determine header area to display on all pages. Cut Header off

Second: Repeat first step now with footer and then navigation bar. 
Note: When you layout page first time, use tables to enclose navbar, header, footer areas. This makes it easier to cut them out later.

Third: Paste each of these sections to blank html page and save each as follows:
  • header.html
  • footer.html
  • navbar.html
  • index.phtml
  • Now you can open them to update that section. But how do we include them on our pages in the correct areas?

    Fourth: Use tags with this format to include those sections of your page we cut out. 

    <? include("header.html"); ?>
    <? include("footer.html"); ?>
    <? include("navbar.html"); ?>

    Of course, upload all files to same directory!

    A simple PHP MySQL query for One value

    This script will query a MySQL database for on value in this case being username. You can query any single value you want, I just went for the obvious username here. 

    Once queried, the script returns the query page again if username un-available. The script returns an adduser form page if username available. One of the fields of our MySQL table is username.

    You will Have to change these items for the script to work: 
    yourusername
    yourpassword
    yourdatabasename

    And if your database table is named something other than users, change also.

    Cut and paste the below code to a notepad first or you will get strange characters. Then save your files and upload.

    <!-- Start PHP query MySQL database -->
    <-- Save this file as query.phtml for loop to work -->
    <?
    //* First establish database variable and connect to database
    $db = @mysql_connect("localhost","yourusername","yourpassword") 
    or die(mysql_error());
    mysql_select_db("yourdatabasename")
    or die(mysql_error());
    //* now query table named users for existing username
    $query = mysql_query( "SELECT * FROM users WHERE username='$username'",$db);
    //* count affected rows in database to see if username exist
    $count = mysql_affected_rows($db);
    //* Now a simple loop with if-else statemaent.
    //* If username has not been entered into your database, adduser.txt is displayed next
    //* allowing complete information to enter into database - adduser.txt is an HTML form.
    {
    if (!$query==$count) {
    echo "Username <b>$username</b> available<br>";
    echo "<b>$username</b> authorized here.";
    include("adduser.txt");
    } else {
    echo "Try again";
    include("query.phtml");
    }

    {
    mysql_close($db);

    }
    }
    ?>
    <-- end script -->

    If you have specific questions about this code or want more, send email to scripts @ Cyberiot.com (no spaces)

    • The ability to setup custom settings in PHP( i.e. include_path, error_log, log_errors, sendmail_from...).
      The settings can be set in the actual PHP script using the command 'ini_set'. [Notice that the On/Off setting is now set with 1/0]. 

      Example of this:
      ----------------------------------------------------
      <?
      ini_set("include_path", "./:/usr/local/lib/php:/home/$user/www/php/");
      ini_set("auto_prepend_file", "/home/$user/www/php/prepend.php3");
      ini_set("error_log", "/home/$user/www/php/error_log");
      ini_set("track_vars", 1);
      phpinfo();
      ?>
      ----------------------------------------------------

      [FYI: 'track_vars' is not used in PHP4, but is included so that the examples are consistant throughout. ;-)]
    • How do I work with a MySQL database using PHP?

      1.To merely display the information in your database without the use of a form to call a php script you simply create your HTML document as you would any other web page but instead of the extension of .htm or .html you need to name the file with the extension .phtml. Then within the document itself the section that you'd like to be the PHP code, you begin it with <? and end it with ?>. For instance: 

      <P>These are the products I sell:</P>

      <TABLE BORDER="1">

      <?
      mysql_connect("localhost", "database_user_name", "password");
      $result = mysql(mydatabase, "select * from products");
      $num = mysql_numrows($result);
      $i = 0;

      while($i < $num) {
      echo "<TR>n";
      echo "<TD>n";
      echo mysql_result($result,$i,"prodid");
      echo "</TD>n<TD>";
      echo mysql_result($result,$i,"name");
      echo "</TD>n<TD>";
      echo mysql_result($result,$i,"price");
      echo "</TD>n";
      echo "</TR>n";
      $i++;}
      ?>
      </TABLE>

      Thus having the loop in the php program create a table with the products listed. NOTE your database user name and password for the database are not written in the file when it's displayed on the Internet so users viewing the source of your webpage will not see your password. [note that database_user_name and password are replaced above with your db user name and password; localhost is not replaced]

      2.When using a CGI script to pull information from a form which has been submitted by a browser you must have the first line of the script have this command on it (Much like perl scripts):

      #!/usr/local/bin/php

    • A simple information call to PHP 

      Just change it to a html file and call it what you want, them upload to your main directory 'yourdomain-www' 

      Call the file in your browser. You will see modules and most info you'll need.
      =========

      <html>
      <body>

      <?php phpinfo()?>

      </body>
      </html>


      =========
      »Delete this html file from your online directory after viewing«

    • PHP Syntax

      phpMyAdmin does not stop the user from entering incorrect syntax, therefore it will accept a line like the one below even though it is incorrect:

      Bad:

      ALTER TABLE bmt_userinfo ADD first_name TEXT (25) not null , ADD last_name TEXT (25) not null , ADD address1 TEXT (100) not null , ADD address2 TEXT (100) not null , ADD city TEXT (30) not null;

      However the same line minus the text length does work:

      Good:

      ALTER TABLE bmt_userinfo ADD first_name TEXT not null , ADD last_name TEXT not null , ADD address1 TEXT not null , ADD address2 TEXT not null , ADD city TEXT not null;

      This is because "TEXT" is a set length. 

      Important: Any syntax that will not work on the command line, will not work in phpMyAdmin either.

      A good place to find out correct syntax for a command that you want to perform is:
      "http://www.mysql.com/documentation/index.html"

    • PHP Syntax and XML calls

     


    In-link is a powerful portal solution that allows you to run a complex Yahoo-style directory directly on your web site without having to update numerous HTML pages. All of the information is stored in an SQL database and therefore is easily updateable. 

     

    Cyberiot
    Newsletter

    Learning Series / HOW-TO create dynamic Webs

    We write our own newsletter which is distributed free of charge. Articles of value, cut-and-paste scripts, free resources and success stories. 

    Opt out at any time, no obligation to buy a single thing. We won't bore you with a million articles each week, short and to the point. Begin learning today.

    • How can scripts help me? 
    • Do I need a Database?
    • What to do with it!

    What to expect?

    • MySQL tutorial
    • PHP tutorial
    • Cut and Paste codes to get you going
    • Simple layman's solutions for your site and budget problems
    • How-to save big bucks with small codes
    Your Name:
    Your E-mail Address:

     



    Home FAQ Hosting Servers Support Contact
    Search Domain Search Domain Renewal Affiliate Pass this on Policy

    CyberRiot.net services may not be used for sites containing or linking to nudity or other pornographic material, illegal material, or other objectionable content.

    Security software monitors our network every second of every day. Spamming software or porn are not allowed.

    © Copyright 1999 - 2002 Cyberiot.com
    All Rights Reserved