Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 09-07-2008, 09:30 AM   #1 (permalink)
landonmkelsey
Code Monkey
 
Join Date: Aug 2008
Posts: 75
landonmkelsey is on a distinguished road
template for a web site in Fedora 9 using php and mysql

anybody interested here is the php:

A few easy mysql commands are req'd to set up database!

A few easy steps set up httpd to make your computer a web server in minutes!

even though you don't have a static IP. I have to use a port of 8080 since my ISP blocks port 80.
// put the php code in

/var/www/html

Don't since I am a beginner at web sites!

Later you can use your own database table!

Code:
<?php

///DB CONNECTION
/* Connect to MySQL server and select database. */
    $conn = mysql_connect("localhost","landon4","_______3141")
        or die ('Could not connect: '.mysql_error());

    mysql_select_db("landon4_logbook")
        or die("Could not select database");
///////
//construct a global variable for the form profile
$fields = array('fdate', 'actype', 'acid', 'nlandings', 'nhours');
///

// If the submit button has been pressed
if (isset($_POST['select'])){
    displayDeleteForm();
}elseif(isset($_POST['delete'])){
    deleteRecords();
} elseif(isset($_POST['insert'])){
    insertRecord();
} elseif (isset($_POST['new'])){
    displayEntryForm();
} else {
    //default action
    displayEntryForm();
}


function displayDeleteForm(){
    //get $fields into the function namespace
    global $fields;
/* Create and execute query. */
//     $query = "select * from log_book";
//     $result = mysql_query($query);
// Loop through each row, outputting the actype and name
     echo <<<HTML
    Pilots Logbook entries stored in mySQL Relational Database
under Redhat Fedora 8 Linux
    <form action="{$_SERVER['PHP_SELF']}" method="post">
    <table width="50%" align="center" border="1">
    <tr>
        <th>checked</th>
        <th>rowID</th>
        <th>fdate</th>
        <th>actype</th>
        <th>acid</th>
        <th>nlandings</th>
        <th>nhours</th>
    </tr>
HTML;

    //get log_book table information
    $user = "select * from log_book";
    $result = mysql_query($user) or die(mysql_error());

    //display log_book information
    $count = 0;

    while ($newArray = mysql_fetch_assoc($result)) {
        foreach ($fields as $field){
            ${$field} = $newArray[$field];
        }
        $rowID = $newArray['rowID'];
        //note that we do not rely on the checkbox value as not all browsers submit it
        //instead we rely on the name of the checkbox.
        echo <<<HTML
    <TR>
        <td>
            <input type="checkbox" name="checkbox[$rowID]" value="$rowID">Check to delete record
        </td>
        <TD>$rowID</TD>
        <TD>$fdate</TD>
        <TD>$actype</TD>
        <TD>$acid</TD>
        <TD>$nlandings</TD>
        <TD>$nhours</TD>
    </TR>

HTML;

    }    // while
    echo <<<HTML
    <tr>
        <td colspan="7">
            <input type="submit" name="delete" value="delete checked items"/>&nbsp;
            <input type="submit" name="new" value="New Log Entry" />&nbsp;
            <input type="reset" name="reset" value="Reset Form" />
        </td>
    </tr>
    </table>
    </form>

HTML;
}    //close function


// ................................................................. DELETE
// code from a book "Beg PHP and MySQL 5" by Gilmore

function deleteRecords(){

// Loop through each log_book with an enabled checkbox
    if (!isset($_POST['checkbox'])){
        return true;
    }
    //else

    foreach($_POST['checkbox'] as $key=>$val){
        $toDelete[] = $key;
    }
    //expand the array for an IN query
    $where = implode(',', $toDelete);

    $query = "DELETE FROM log_book WHERE rowID IN ($where)";

    $result = mysql_query($query);

    // Should have one affected row
    if ((mysql_affected_rows() === 0) || !$result) {
        echo "<p>There was a problem deleting some of the selected items.</p><p>".mysql_error().'</p>';
        exit();
    } else {
        echo "<p>The selected items were successfully deleted.</p>";
    }
    //direct the user back to the delete form
    displayDeleteForm();
} //end function


function insertRecord(){

    // Retrieve the posted log book information.
    global $fields;
    //add some very crude validation
    foreach ($fields as $field){
        if (empty($_POST[$field])){
            $messages[] = "You must complete the field $field \r\n";
        } else {
            $dFields[$field] = mysql_real_escape_string(trim($_POST[$field]));
        }
    }
    if (count($messages)>0) {
        displayEntryForm($messages, $dFields);
        exit();
    }
    //end validation

    //get variables into the namespace
    extract($dFields);
    // Insert the log book information into the log book table
    $query = "INSERT INTO log_book SET fdate='$fdate', actype='$actype',
acid='$acid', nlandings='$nlandings', nhours = '$nhours'";

    $result = mysql_query($query);

// Display an appropriate message
    if ($result) {
        echo "<p>Product successfully inserted!</p>";
    }else {
        echo "<p>There was a problem inserting the log book!</p>";
    }
    //direct the user back to the entry form

    displayEntryForm();
}

function displayEntryForm($errorMessages=null, $dFields=null){
    if (!empty($errorMessages)){
        echo "<ul><li>".explode('</li><li>', $errorMessages) . "</li></ul>";
    }

    //sort out field values
    global $fields;
    foreach ($fields as $field){
        if (isset($dFields[$field])){
            ${$field} = $dFields[$field];
        } else {
            ${$field} = '';
        }
    }

    echo <<<HTML
<form action="{$_SERVER['PHP_SELF']}" method="post">
<p>
Flight Date:<br />
<input type="text" size="20" maxlength="40" name="fdate"
value="$fdate" />
</p>
<p>
Aircraft Type:<br />
<input type="text" size="20" maxlength="40" name="actype"
value="$actype" />
</p>
<p>
Aircraft ID:<br />
<input type="text" size="20" maxlength="40" name="acid"
value="$acid" />
</p>
<p>
Number Landings:<br />
<input type="text" size="20" maxlength="40" name="nlandings"
value="$nlandings" />
</p>
<p>
Number Hours:<br />
<input type="text" size="20" maxlength="40" name="nhours"
value="$nhours" />
</p>
<button type="submit" name = "insert" value="Insert Row!"
style="color:maroon font:18pt Courier; font-weight:bold ">Insert Row
</button>
<button type="submit" name = "select" value="Show All!"
style="color:red font:18pt Courier; font-weight:bold ">Show All
</button>
<button type="submit" name = "delete" value="Delete Row!"
style="color:red font:18pt Courier; font-weight:bold ">Delete Row!
</button>
</form>
HTML;
} //end display function
?>
landonmkelsey is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
xml - php - mysql Hooch HTML, XML, Javascript, AJAX 5 05-23-2006 04:32 AM
Flash8, PHP and MySQL Redline All Other Coding Languages 2 05-02-2006 10:04 PM
Help with outside connection to mysql using a php page ericanca PHP 11 07-19-2005 10:33 AM
Help with outside connection to mysql using a php page ericanca Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 1 04-18-2005 07:37 PM
cant connect to mysql databases using php eran PHP 11 08-07-2004 08:02 AM


All times are GMT -8. The time now is 12:36 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting