|
|
|
|
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 | | | Pull Down Surfing - Surf on Change Categories : Java Script, MySQL, HTML and PHP, PHP, 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 | | | A Simple sign up script with PHP and JavaScript validations. Categories : PHP, Java Script, MySQL, Databases | | | 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 | | | 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 | | | 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 | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, 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 | | | email new items in db Categories : PHP, Email, Databases, MySQL, Beginner Guides | | | Alternating background color for HTML table rows Categories : PHP, Databases, MySQL, HTML and PHP | | | color codes for positive and negative numbers Categories : PHP, MySQL, Databases, HTML | | | mysql_escape_string Categories : PHP, MySQL, Databases, Strings | |
|
|
|