Database Articles

  Home arrow Database Articles arrow Page 10 - Create dynamic sites with PHP & MySQL
DATABASE ARTICLES

Create dynamic sites with PHP & MySQL
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 54
    2002-05-19

    Table of Contents:
  • Create dynamic sites with PHP & MySQL
  • Introduction and installation
  • Installing Apache server routines
  • Installing MySQL
  • Installing PHP
  • Your first script
  • Your first database
  • Where's my view?
  • Creating an HTML form
  • Putting it together
  • Passing variables
  • Viewing individual rows
  • Deleting rows
  • Editing data
  • Searching our data
  • Tips for common tasks

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Create dynamic sites with PHP & MySQL - Putting it together


    (Page 10 of 16 )

    Now let's merge the code into one file. We will call it input.php

    <HTML> 
    <?php 
    if($submit) 

    $db = mysql_connect("localhost", "root",""); 
    mysql_select_db("learndb",$db); 
    $sql = "INSERT INTO personnel (firstname, lastname, nick, email, salary) VALUES ('$first', '$last', '$nickname','$email','$salary')";
    $result = mysql_query($sql); 
    echo "Thank you! Information entered.\n"; 

    else 

    ?> 
    <form method="post" action="input.php"> 
    First name:<input type="Text" name="first"><br> 
    Last name:<input type="Text" name="last"><br> 
    Nick Name:<input type="Text" name="nickname"><br> 
    E-mail:<input type="Text" name="email"><br> 
    Salary:<input type="Text" name="salary"><br> 
    <input type="Submit"name="submit" value=" Enter information"></form> 
    <? 

    ?> 
    </HTML>

    This creates a script that shows the form when there is no input or otherwise enters the information into the database. How does the script understand when to do what? We have already learned that PHP automatically creates variable with information posted to it. So it will create the variable $submit if the form is posted. The script determines whether there exists the variable $submit. If it exists and contains a value then we have to enter the posted values into the database; otherwise, we have to show the form.

    So now we can enter information to our database and view it. Try inserting some new data into the database and check to see if it really works by viewing them with viewdb.php.

    More Database Articles Articles
    More By Codewalkers

    blog comments powered by Disqus

    DATABASE ARTICLES ARTICLES

    - Completing a Book Inventory Management System
    - Uploading Images for a Book Inventory Manage...
    - Finishing the Add Book Story for a Book Inve...
    - Integration Testing for a Book Inventory Man...
    - User Stories for a Book Inventory Management...
    - Unit Testing a Book Inventory Management Sys...
    - Testing a Book Inventory Management System
    - Implementing Models for a Book Inventory Man...
    - Book Inventory Application: Publishers and B...
    - Handling Publishers in a Book Inventory Mana...
    - Publisher Administration for Book Inventory ...
    - Book Inventory Management
    - Using the SQL Reference Manual
    - Using Oracle SQL Developer with SQL Statemen...
    - Fixing Errors with Oracle SQL Developer


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap