First the PHP section
First of all.
We have to define the connection.
we will name this page as connection.php
the code-
$link=mysql_connect('127.0.0.1','root','');
if(!$link)
{
die('Error Connecting to Server. '.mysql_error());
}
$select_db=mysql_select_db('telephone',$link);
if(!$select_db)
{
die('Error Connecting to Database '.mysql_error());
}
// clear the cache
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
$ExpStr = "Expires: " . gmdate("D, d M Y H:i: s ", time() ) . " GMT";
header($ExpStr);
header('Cache-Control: public, no-cache');
?>
Now the main page.
I have named it as "resultname.php"
code-
include("connection.php");
$searchname = $_REQUEST['searchname'];
if($_REQUEST["ADD"])
{
$id = $_REQUEST['id'];
$name = $_REQUEST['name'];
$mobile1 = $_REQUEST['mobile1'];
$mobile2 = $_REQUEST['mobile2'];
$mobile3 = $_REQUEST['mobile3'];
$lan1 = $_REQUEST['lan1'];
$lan2 = $_REQUEST['lan2'];
$address = $_REQUEST['address'];
$email = $_REQUEST['email'];
mysql_query("insert into record
(name,mobile1,mobile2,mobile3,lan1,lan2,address,email)
values
('$name','$mobile1','$mobile2','$mobile3','$lan1','$lan2','$address','$email')");
if(mysql_affected_rows() > 0)
{
$msg = "Records Inserted Successfully";
}
else
{
$msg = "Error! record not inserted";
}
}
if($_REQUEST['mode']=="add")
{?>
}
if($_REQUEST["Update"])
{
$id = $_REQUEST['id'];
$name = $_REQUEST['name'];
$mobile1 = $_REQUEST['mobile1'];
$mobile2 = $_REQUEST['mobile2'];
$mobile3 = $_REQUEST['mobile3'];
$lan1 = $_REQUEST['lan1'];
$lan2 = $_REQUEST['lan2'];
$address = $_REQUEST['address'];
$email = $_REQUEST['email'];
$sql = "UPDATE record SET
name = '$name' , mobile1 = '$mobile1' , mobile2 = '$mobile2' , mobile3 = '$mobile3' , lan1 = '$lan1' , lan2 = '$lan2' , address = '$address' , email = '$email' WHERE id='$id'";
$result = mysql_query($sql);
if(mysql_affected_rows()>0)
{
$msg = "Updation Completed Successfully";
}
else
{
$msg = "Updation failed";
}
}
if($_REQUEST['mode']=="edit")
{
$result = mysql_query("select * from record where id=".$_GET['id']);
$myrow = mysql_fetch_array($result);?>
" onClick="return confirm('Are You Sure ?)">
-->
}
if($_REQUEST['mode']=="delete")
{
mysql_query("delete from record where id=".$_GET['id']);
$msg = "Record Deleted Successfully.";
}
?>
$total = mysql_query("SELECT count(*) as cnt FROM record where name like '%$searchname%' or mobile1 like '%$searchname%' or mobile2 like '%$searchname%' or mobile3 like '%$searchname%' or lan1 like '%$searchname%' or lan2 like '%$searchname%'");
$a = mysql_fetch_object($total);
$total_items = $a->cnt;
//echo "Total Number of records in Database: ".$total_items;
$limit= 10;
$page= $_GET['page'];
echo '' . $set_limit . '';
if((!$limit) || (is_numeric($limit) == false)
|| ($limit <> 50))
{
$limit = 10; //default
}
//Set default if: $page is empty, non numerical,
//less than zero, greater than total available
if((!$page) || (is_numeric($page) == false)
|| ($page <> $total_items))
{
$page = 1; //default
}
$total_pages = ceil($total_items / $limit);
$set_limit = ($page * $limit) - $limit;
$sql="SELECT * FROM record where name like '%$searchname%' or mobile1 like '%$searchname%' or mobile2 like '%$searchname%' or mobile3 like '%$searchname%' or lan1 like '%$searchname%' or lan2 like '%$searchname%' order by name LIMIT $set_limit, $limit";
$sql_query=mysql_query($sql);
while($row=mysql_fetch_array($sql_query))
{
?>
}
Now the MY SQl Section-
we will create a database named telephone
and then paste the following code
CREATE TABLE IF NOT EXISTS `record` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`mobile1` varchar(15) NOT NULL,
`mobile2` varchar(15) NOT NULL,
`mobile3` varchar(15) NOT NULL,
`lan1` varchar(15) NOT NULL,
`lan2` varchar(15) NOT NULL,
`address` varchar(100) NOT NULL,
`email` varchar(50) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
)
