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
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
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



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 : A Complete table(ADD,EDIT,VIEW,DELETE) management System PHP,MYSQL, JAVASCRIPT
Categories : PHP, MySQL, Java Script, Databases
Suraj Thapaliya
Date : May 05th 2006
Grade : 3 of 5 (graded 100 times)
Viewed : 156652
File : 4392.zip
Images : No Images for this code example.
Search : More code by Suraj Thapaliya
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
Like this code?
Show the author your appreciation.
 

in this example i had cover the ADD,EDIT,DELETE and VIEW of table which had multiple deletion with select all feature from javascript interactive with PHP



Connection File
<?php
$db_name
="general_suraj";// Database name
$connection=mysql_connect("hostname","username","password") or die("I Couldn't connect");
$db=mysql_select_db($db_name,$connection) or die("I Couldn't select your database");
$branch="emp_branch"; // Table name
?>



index.php - The main Index File
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Branch</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript" src="script.js"> </script>
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style>
</head>

<body>
<table width="775" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td><hr size="1" noshade></td>
  </tr>
  <tr>
    <td>
      <form action="" method="post" name="" id="">
        <table width="600" border="1" align="center" cellpadding="2" cellspacing="2">
          <tr>
            <td><input name="topcheckbox" type="checkbox" class="check" id="topcheckbox" onClick="selectall();" value="ON">
Select All    </td>
            <td colspan="3" align="center"><a href="form.php?mode=add">Add New Branch </a></td>
          </tr>
          <tr>
            <td><strong><a href="javascript:goDel()">Delete</a></strong></td>
            <td><strong>Branch Name </strong></td>
            <td><strong>Short Name </strong></td>
            <td><strong>Update</strong></td>
          </tr>
          <?
         
include("conn.php");
         
$sql="select sn,branchname,shortname from $branch order by sn";
         
$result=mysql_query($sql,$connection) or die(mysql_error());
          while(
$row=mysql_fetch_array($result)) {
         
?>
          <tr>
            <td><input name="<? echo $row['sn']; ?>" type="checkbox" class="check"></td>
            <td><? echo $row['branchname']; ?></td>
            <td><? echo $row['shortname']; ?></td>
            <td><a href="<? echo "form.php?sn=".$row['sn']."&mode=update"; ?>">Update</a></td>
          </tr>
          <? } ?>
          <tr>
            <td><strong><a href="javascript:goDel()">Delete</a></strong></td>
            <td><strong>Branch Name </strong></td>
            <td><strong>Short Name </strong></td>
            <td><strong>Update</strong></td>
          </tr>
        </table>
    </form></td>
  </tr>
</table>
</body>
</html>


delete.php - Delete file
<?php
include("conn.php");
$recsno=$_GET["recsno"];
$data=trim($recsno);
$ex=explode(" ",$data);
$size=sizeof($ex);
for(
$i=0;$i<$size;$i++) {
   
$id=trim($ex[$i]);
   
$sql="delete from $branch where sn='$id'";
   
$result=mysql_query($sql,$connection) or die(mysql_error());
   
}
header("location: index.php");
?>




form.php - Update And Add Record Form File
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Branch</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table width="775" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td> </td>
  </tr>
  <tr>
    <td>      <table width="700" border="0" align="center" cellpadding="2" cellspacing="2">
        <tr>
          <td> </td>
        </tr>
        <tr>
          <td>
          <?
          $mode
=$_GET["mode"];
          if(
$mode=="add") {
         
?>
          <form name="form1" method="post" action="formsubmit.php?mode=add">
            <table width="500" border="1" align="center" cellpadding="2" cellspacing="2">
              <tr>
                <td><strong>Add New Branch </strong></td>
                <td> </td>
              </tr>
              <tr>
                <td>Branch Name </td>
                <td><input name="branchname" type="text" id="branchname"></td>
              </tr>
              <tr>
                <td>Short Name</td>
                <td><input name="shortname" type="text" id="shortname"></td>
              </tr>
              <tr>
                <td><input type="submit" name="Submit" value="Save Data"></td>
                <td> </td>
              </tr>
            </table>
          </form>
          <?       
         
} else  {
              include(
"conn.php");
           
$sn=$_GET["sn"];
           
$sql="select sn,branchname,shortname from $branch where sn='$sn'";
           
           
$result=mysql_query($sql,$connection) or die(mysql_error());
            while(
$row=mysql_fetch_array($result)) {
               
$sn=$row['sn'];
               
$branchname=$row['branchname'];
               
$shortname=$row['shortname'];
            }
       
?>
        <form name="form1" method="post" action="formsubmit.php?mode=update">
            <table width="500" border="1" align="center" cellpadding="2" cellspacing="2">
              <tr>
                <td><strong>Update Branch </strong></td>
                <td><input type="hidden" name="sn" value="<? echo $sn; ?>">
                   </td>
              </tr>
              <tr>
                <td>Branch  Name </td>
                <td><input name="branchname" type="text" id="branchname" value="<? echo $branchname; ?>"></td>
              </tr>
              <tr>
                <td>Short Name </td>
                <td><input name="shortname" type="text" id="shortname" value="<? echo $shortname; ?>"></td>
              </tr>
              <tr>
                <td><input type="submit" name="Submit" value="Update Data"></td>
                <td> </td>
              </tr>
            </table>
          </form>
       
        <?   
           
         
}
         
?>
         
          </td>
        </tr>
        <tr>
          <td> </td>
        </tr>
    </table></td>
  </tr>
</table>
</body>
</html>



formsubmit.php - Update and submit new record file
<?php
         
include("conn.php");
         
$mode=$_GET["mode"];
          if(
$mode=="add") {
             
$branchname=$_POST["branchname"];
           
$shortname=$_POST["shortname"];
           
$sql="insert into $branch(branchname,shortname) values('$branchname','$shortname')";
           
$result=mysql_query($sql,$connection) or die(mysql_error());
           
header("location: index.php");
           
          } elseif(
$mode=="update") {
             
$branchname=$_POST["branchname"];
           
$shortname=$_POST["shortname"];
           
$sn=$_POST["sn"];
           
$sql="update $branch set branchname='$branchname',shortname='$shortname' where sn='$sn'";
           
//echo $sql;
           
$result=mysql_query($sql,$connection) or die(mysql_error());
           
header("location: index.php");
          }
         
?>
// Javascript File Script.js
function goDel()
{
    var recslen =  document.forms[0].length;
    var checkboxes=""
    for(i=1;i<recslen;i++)
    {
        if(document.forms[0].elements[i].checked==true)
        checkboxes+= " " + document.forms[0].elements[i].name
    }
   
    if(checkboxes.length>0)
    {
        var con=confirm("Are you sure you want to delete");
        if(con)
        {
            document.forms[0].action="delete.php?recsno="+checkboxes
            document.forms[0].submit()
        }
    }
    else
    {
        alert("No record is selected.")
    }
}

function selectall()
{
//        var formname=document.getElementById(formname);

        var recslen = document.forms[0].length;
       
        if(document.forms[0].topcheckbox.checked==true)
            {
                for(i=1;i<recslen;i++) {
                document.forms[0].elements[i].checked=true;
                }
    }
    else
    {
        for(i=1;i<recslen;i++)
        document.forms[0].elements[i].checked=false;
    }
}
?>










Linked comboboxes with php-mysql & javascript
Categories : PHP, Java Script, Databases, MySQL
Building dynamic menus with PHP & MySQL (ADO), JavaScript and CSS
Categories : PHP, Databases, MySQL, Java Script, User Interface
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
AJAX Data Grid System using php and mysql. A complete login system with the ability to display data in a grid using ajax. Add , update and delete the records without reloading the page.
Categories : PHP, AJAX, Databases, MySQL, Java Script
Pull Down Surfing - Surf on Change
Categories : Java Script, MySQL, HTML and PHP, PHP, Databases
A Simple sign up script with PHP and JavaScript validations.
Categories : PHP, Java Script, MySQL, Databases
In Mysql, the 'datetime' data type is used to store date that looks like '2007-10-16 16:26:30'. we are going to design a function called mysqldate() that takes a mysql date and output format as input and outputs a well formated date.
Categories : PHP, Date Time, Databases, MySQL
Finds the median in an array of numbers - Can be used with a MySql database column read into an array
Categories : PHP, Arrays, 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
A login page that require username, password and userlevel.
Categories : PHP, Security, Sessions, MySQL, Databases
Database resultset navigation
Categories : PHP, HTML and PHP, Databases, MySQL, Navigation
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
PHP Transfer data from text file to Mysql Table
Categories : PHP, PHP Classes, Filesystem, Databases, MySQL
 carlos avila wrote : 1872
can you provide a sample DB schema for newbies.
 
 ec tech wrote :1934
something wrong in index.php, it is unable to get data from database