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 : 162074
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;
    }
}
?>










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
Linked comboboxes with php-mysql & javascript
Categories : PHP, Java Script, Databases, MySQL
Pull Down Surfing - Surf on Change
Categories : Java Script, MySQL, HTML and PHP, PHP, Databases
Building dynamic menus with PHP & MySQL (ADO), JavaScript and CSS
Categories : PHP, Databases, MySQL, Java Script, User Interface
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
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
A Simple sign up script with PHP and JavaScript validations.
Categories : PHP, Java Script, MySQL, Databases
email new items in db
Categories : PHP, Email, Databases, MySQL, Beginner Guides
The simple counter with use MySql and gd.
Categories : MySQL, HTTP, Graphics, PHP, Databases
GroupIT Engine v1.00rc1
Categories : PHP, Content Management, MySQL, Databases
mySQL/PHP/search with multientry form and table output with colored rows
Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases
This simple function will take a few arguments and easily set a associative array for each column in a result from a MySQL query
Categories : Databases, PHP, MySQL, Arrays
Newbie Notes #4 - Trapping dumb MySQL query errors
Categories : PHP, Databases, MySQL, Debugging, Beginner Guides
TAB_STRUCT Class: Is supporting Class for the DBXML Class
Categories : PHP, PHP Classes, MySQL, XML, Databases
Ajax PHP Tree (Left and Right) with MySQL
Categories : PHP, Databases, MySQL, AJAX, PHP Classes
 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