WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : PHP-CSL PHP Code Snippet Library, A very handy application designed to save you many hours by storing all your code snippets, classes and functions.
Categories : PHP, Utilities, MySQL, Databases, To PHP Update Picture
stuart cochrane
Date : Jul 23rd 2002
Grade : 5 of 5 (graded 3 times)
Viewed : 5494
File : snip.php
Images : No Images for this code example.
Search : More code by stuart cochrane
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?
/*
* *********************************
* PHP Code Snippet Library V0.1
* *********************************
*
* *********************************
* Author: Stuart Cochrane
* Email: stuartc1@hotmail.com
* Date: 23-07-2002
* Usage: All comments must remain
* License: GNU Genral Public License
* Message:
* This is my first Open Source
* script in PHP - so any comments are
* very welcome :-)
* **********************************
*
* **********************************
* Description:
* A very basic code snippets library
* designed to hold commonly used code.
* A great way to keep track of your
* handy code snippets, functions and
* classes.
* **********************************
*
* **********************************
* Requirements:
* PHP and MySQL
* Tested on Windows NT4 / IIS 4 / PHP 4.1.2
* with standard configuration -
* but should run on all Platforms.
*
* **********************************
* Configuration:
* Change the mysql database connections
* to match yours - see function con()
* Change the mysql database name
* to match yours - see function sel()
*
* *********************************
* Below is the MySQL dump
* needed to run this app
* *********************************

#
# Table structure for table 'snips'
#
CREATE TABLE `snips` (
`ID` bigint(5) unsigned NOT NULL auto_increment,
`Title` varchar(250) default NULL,
`Body` blob,
`Description` blob,
UNIQUE KEY `ID` (`ID`)
) TYPE=MyISAM;
#
# Dumping data for table 'snips'
#
INSERT INTO snips VALUES("12","Test Snippet",
"echo \"This is the test snippet...\";",
"just a test to get started with.");

*/


// database connection
        function con() {
                return mysql_connect("localhost", "root");
        }
// database selection
        function sel() {
                return mysql_select_db("snippets");
        }
// display the code in colour
function dis($body) {
                $h_string = "<"."?\n\n".$body."\n\n?".">";
                return highlight_string("$h_string");
        }
// retrieve the code from the database
        function hs($view) {
        $db = con();
        sel();
        $snip_sql = "SELECT Body FROM snips WHERE ID = $view";
        $snip_qry = mysql_query($snip_sql, $db);
while ($snip = mysql_fetch_array($snip_qry)) {
        dis($snip["Body"]);
}
}
// retrieve the code description from the database
        function hsd($view) {
        $db = con();
        sel();
        $snip_sql = "SELECT Description FROM snips WHERE ID = $view";
        $snip_qry = mysql_query($snip_sql, $db);
while ($snip = mysql_fetch_array($snip_qry)) {
        echo $snip["Description"];
}
}
// retrieve and display the code titles
function title($delete = "no") {
        $db = con();
        sel();
$snip_sql = "SELECT ID, Title FROM snips ORDER BY Title";
$snip_qry = mysql_query($snip_sql, $db);
while ($snip = mysql_fetch_array($snip_qry)) {

        $title = $snip["Title"];
        $id = $snip["ID"];
                        if ($delete == "no") {
                echo "<a href=\"snip.php?view=$id\">$title</a><br>";
                        } else {
                                echo "<a href=\"snip.php?
opt=del&id=$id\">$title</a><br>";
                        }
}
}
// add a snippet to the database
        function asnip($title,$code,$description = "none") {
                $db = con();
        sel();
                $snip_sql = "        INSERT INTO snips (Title, Body, Description)
                                                VALUES
('$title', '$code', '$description')";
                if (! mysql_query($snip_sql)){
                        echo mysql_error();
                        die;
                } else { return true; }
        }
// delete snippet from the database
        function dsnip($id) {
                $db = con();
        sel();
                $snip_sql = "        DELETE FROM snips
                                                WHERE ID = $id";
                if (! mysql_query($snip_sql)){
                        echo mysql_error();
                        die;
                } else { return true; }
        }
// build the start of a table
        function tstart($class, $width) {
                if($class == 1) {
        echo '<table class="table1" width="'.$width.'" cellpadding="2">
                <tr>
                        <td>';
                } else {
                        echo '<table class="table2" width="'.$width.'"
cellpadding="2">
                <tr>
                        <td>';
                }
        }
// build the end of a table
        function tend() {
        echo '</td>
                </tr>
                </table>';
        }

// set the header vars
$appname= '<b>PHP-CSL</b>';
$appversion = '<i>PHP Code Snippet Library V0.1</i>';

// get the diplay type
if (isset($opt)) {
        if ($opt == "add") {
                $DoThis = "add";
        } elseif ($opt == "del") {
                $DoThis = "del";
        }
} else {
        $DoThis = "snippets";
}
?>

<style>
        BODY {
        background-color : #FFFFFF;
        color : #000000;
        font-family : Arial, Helvetica, sans-serif;
        font-size: 11px;
        font-weight : normal;
        background-attachment:fixed;
        scrollbar-arrow-color: 000000;
        scrollbar-track-color: ffffff;
        scrollbar-face-color: E9E9E9;
        scrollbar-highlight-color: ffffff;
        scrollbar-3dlight-color: 000000;
        scrollbar-darkshadow-color: 000000;
        scrollbar-shadow-color: 000000;
        }
        .table1 {
        background-color: #E9E9E9;
        border-color: #000000 #000000 #000000 #000000;
        border-style: solid;
        border-top-width: 1px;
        border-right-width: 1px;
        border-bottom-width: 1px;
        border-left-width: 1px;
        font-family: Arial, Helvetica, sans-serif;
        font-size: 12px;
        font-weight: normal;
        color: #000000
        }
        .table2 {
        background-color: #FFFFFF;
        border-color: #000000 #000000 #000000 #000000;
        border-style: solid;
        border-top-width: 1px;
        border-right-width: 1px;
        border-bottom-width: 1px;
        border-left-width: 1px;
        font-family: Arial, Helvetica, sans-serif;
        font-size: 12px;
        font-weight: normal;
        color: #000000
        }
        .submit {
        background-color: #E9E9E9;
        font-family: Arial, Helvetica, sans-serif;
        font-weight: bold;
        font-size: 11;
        color: #000000;
        text-decoration:none;
        }
</style>
<? // draw the header
        tstart(1, "100%");
                echo '<a href="snip.php">'.$appname.'</a> - '.$appversion;
        tend();
        echo "<br>";
?>

<? if ($DoThis == "add") { //START ADD SNIPPETS
if(isset($submit)) { // add the snippet to the database
        if (asnip($title,$code,$description)) {
                echo '        <script language="javascript">
                                        alert("The snippet was added.");
                                        document.location="snip.php";
                                </script>';
        }
} else { // show the add form
tstart(1,500); ?>
        <script language="javascript">
                function val() {
                        if (document.deletesnip.title.value == "" |
                                document.deletesnip.code.value == "") {
                                alert("You must complete both TITLE and CODE
fields.");
                                return false;
                                }
                        else {
                                return true;
                        }
                }
        </script>
<form name="deletesnip" method="post" action="snip.php?opt=add" onSubmit="return
val
();">
        <b>Snippet Title: *</b><br>
        <input type="text" name="title" size="65"><br><br>
        <b>Snippet Code: *</b><br>
        <textarea cols="55" rows="15" name="code"></textarea><br><br>
        <b>Snippet Description:</b><br>
        <textarea cols="55" rows="6" name="description"></textarea>
        <p align="center">
                <input type="submit" name="submit" class="submit" value="Add Snippet
>>">
        </p>
</form>
<?
tend();
}
} // END ADD ?>


<? if ($DoThis == "del") { //START DELETE SNIPPETS
if(isset($id)) { // delete snippet from the database
        if (dsnip($id)) {
                echo '        <script language="javascript">
                                        alert("The snippet was deleted.");
                                        document.location="snip.php";
                                </script>';
        }
} else { // show available snippets
tstart(1,200);
                tstart(2,"100%");
                        echo "<b>Select one to delete:</b>";
                tend();
        title("yes");
tend();
}
} // END DELETE ?>


<? if ($DoThis == "snippets") { // START SNIPPETS PAGE ?>
<table width="100%" cellpadding="2" border="0">
        <tr valign="top">
                <td width="200">

        <?
                tstart(1, 200);
                        // show header
                        tstart(2, "100%");
                        echo "<b>Snippets:</b>";
                        tend();
                title();
                        echo "<br><br>";
                        tstart(2, "100%");
                        echo "<b>Options:</b><br>";
                        tend();
                        echo '<a href="snip.php?opt=add">Add Snippet</a><br>';
                        echo '<a href="snip.php?opt=del">Delete Snippet</a>';
                tend();
        ?>
</td>
<td valign="top" align="left">
        <?        if (isset($view)) {
                        // show the code
                        tstart(1, 540);
                                // show the code description
                                tstart(2, "100%");
                                echo "<b>Snippet Code:</b>";
                                tend();
                        hs($view);
                                tstart(2, "100%");
                                echo "<b>Description:</b><br>";
                                hsd($view);
                                tend();
                                
                        tend();
                } else {
                        echo " ";
                }
        ?>
</td>
        </tr>
</table>
<? } // END SNIPPETS PAGE ?>



mediaCat-GTK v2.0.0 - an mp3/cd/dvd cataloging utility written in php-gtk which interfaces with mysql and ms access (or db supported by PHP's Unified ODBC Functions)
Categories : PHP, MySQL, MS Access, Utilities, Databases
This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, PHP, Databases
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs.
Categories : Databases, PHP, MySQL, Complete Programs
Cut your MySQL Connections to 1 line of code
Categories : PHP, Beginner Guides, Databases, MySQL
phpAds, a complete banner and ad management system with detailled tracking and stats.
Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases
Point and Click Interface ala MS Access for creating SQL statements.
Categories : MySQL, Complete Programs, General SQL, PHP, Databases
Displaying records of database in more than one page (paging)
Categories : Databases, MySQL, PHP
html split bar used to split in multiple pages a database result
Categories : HTML and PHP, Databases, MySQL, PHP
Tropicalm Genetree Family (MySQL based family tree)
Categories : PHP, Interfaces, Databases, MySQL, Complete Programs
Report Generation in Microsoft Access from a MYSQL database
Categories : PHP, MySQL, Databases, MS Access
Automatically printing the contents of an sql table in MySQL.
Categories : MySQL, PHP, HTML and PHP, Databases
Email a user with out exposing email address
Categories : PHP, Databases, MySQL, Email
http://phpMySearch.web4.hm - The phpMySearch search engine system is a completeworld wide web indexing and searching system for a small domain or intranet.
Categories : Search Engines, PHP, Databases, MySQL
A very simple and efficient split bar the B-Z bar , for mysql and php ... Tired of obfuscated code try this one ...
Categories : PHP, Databases, MySQL, Algorithms