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;
}
}
?>
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 Linked comboboxes with php-mysql & javascript Categories : PHP , Java Script , Databases , MySQL bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager Categories : MySQL , PHP , MySQL , Complete Programs , Databases Building dynamic menus with PHP & MySQL (ADO), JavaScript and CSS Categories : PHP , Databases , MySQL , Java Script , User Interface 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 Password reminder Categories : PHP , PHP Classes , Databases , MySQL , Mail Identify and log search engine access (spiders, robots, etc.) to a page. Categories : HTTP , Environment Variables , PHP , MySQL , Databases A simple script to count and report hits and the last
modification time of an HTML page. Requires MySQL support
(other DBs should work too, except possibly mSQL). Categories : HTTP , MySQL , PHP , Databases The Ajax Tree view class fetches data from a db for the requested parent category id. The data is then stored in an array and converted into JSON (Javascript Object Notation) format. This format is then used by JavaScript for populating tree view. Categories : PHP , PHP Classes , Java Script , AJAX , Databases create a grid out of <INPUT TYPE=TEXT> then saving to a database. Uses
a 'multi-dimension array', but not really as the array is just one big array
with the index of "[$i][$j]". Have a look at the code and you'll see what I
mean. Categories : PHP , MySQL , Arrays , Databases php-gtk mysql querying tool Categories : PHP-GTK , MySQL , PHP , Databases Simple function to return the number of days in a time span between 2 given dates. Categories : PHP , Date Time , MySQL , Databases Specify your connection settings and create a link to a MySQL database. Categories : PHP , PHP Classes , Databases , MySQL , Beginner Guides
carlos avila wrote : 1872
can you provide a sample DB schema for newbies.