WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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 : 9533
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  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 ?>



bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, 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
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
Inserting data to a MySQL Database using AJAX
Categories : AJAX, HTTP, PHP, Databases, MySQL
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
AJAX Application
Categories : PHP, AJAX, Databases, MySQL
How to load a query result into a PHP Array
Categories : PHP, Databases, Arrays, MySQL
phpAds, a complete banner and ad management system with detailled tracking and stats.
Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases
PHP4 AND MySQL Authentication
Categories : PHP, MySQL, Authentication, Databases
Point and Click Interface ala MS Access for creating SQL statements.
Categories : MySQL, Complete Programs, General SQL, PHP, Databases
Report Generation in Microsoft Access from a MYSQL database
Categories : PHP, MySQL, Databases, MS Access
Full membership authentication system.
Categories : Authentication, MySQL, PHP, Databases
Example voting script. Lets people enter suggestions and vote for existing ones.
Categories : MySQL, PHP, Cookies, Complete Programs, Databases
Simple pipe delimited file export program that downloads to a local machine
Categories : PHP, Filesystem, Databases, MySQL, HTTP
A script to generate a report from a valid mysql connection. The user has to supply which fields he wants to display in table. All properties are changable.
Categories : PHP, PHP Classes, Databases, MySQL, HTML and PHP