Try this code
Standards/PHP/PHP_Database
<? session_start(); ?>
<html>
<head>
<title>MY CONTACTS</title>
<meta name="generator" http-equiv="content-type" content="text/html">
<style type="text/css">
body {
background-color: #FFFFFF;
color: #004080;
font-family: Arial;
font-size: 12px;
}
.bd {
background-color: #FFFFFF;
color: #004080;
font-family: Arial;
font-size: 12px;
}
.tbl {
background-color: #FFFFFF;
}
a:link {
color: #FF0000;
font-family: Arial;
font-size: 12px;
}
a:active {
color: #0000FF;
font-family: Arial;
font-size: 12px;
}
a:visited {
color: #800080;
font-family: Arial;
font-size: 12px;
}
.hr {
background-color: #336699;
color: #FFFFFF;
font-family: Arial;
font-size: 12px;
}
a.hr:link {
color: #FFFFFF;
font-family: Arial;
font-size: 12px;
}
a.hr:active {
color: #FFFFFF;
font-family: Arial;
font-size: 12px;
}
a.hr:visited {
color: #FFFFFF;
font-family: Arial;
font-size: 12px;
}
.dr {
background-color: #FFFFFF;
color: #000000;
font-family: Arial;
font-size: 12px;
}
.sr {
background-color: #EFEFEF;
color: #000000;
font-family: Arial;
font-size: 12px;
}
</style>
</head>
<body>
<table class="bd" width="100%"><tr><td class="hr"><h2>My Contacts</h2></td></tr></table>
<?php
if (!login()) exit;
?>
<?php
$conn = connect();
$showrecs = 50;
$pagerange = 10;
$a = @$_GET["a"];
$recid = @$_GET["recid"];
if (isset($_GET["order"])) $order = @$_GET["order"];
if (isset($_GET["type"])) $ordtype = @$_GET["type"];
if (isset($_POST["filter"])) $filter = @$_POST["filter"];
if (isset($_POST["filter_fiel
$wholeonly = false;
if (isset($_POST["wholeonly"]
if (!isset($order) && isset($_SESSION["order"]))
if (!isset($ordtype) && isset($_SESSION["type"])) $ordtype = $_SESSION["type"];
if (!isset($filter) && isset($_SESSION["filter"])
if (!isset($filterfield) && isset($_SESSION["filter_fi
$page = @$_GET["page"];
if (!isset($page)) $page = 1;
$sql = @$_POST["sql"];
switch ($sql) {
case "insert":
sql_insert();
break;
case "update":
sql_update();
break;
case "delete":
sql_delete();
break;
}
switch ($a) {
case "add":
addrec();
break;
case "view":
viewrec($recid);
break;
case "edit":
editrec($recid);
break;
case "del":
deleterec($recid);
break;
default:
select();
break;
}
if (isset($order)) $_SESSION["order"] = $order;
if (isset($ordtype)) $_SESSION["type"] = $ordtype;
if (isset($filter)) $_SESSION["filter"] = $filter;
if (isset($filterfield)) $_SESSION["filter_field"] = $filterfield;
if (isset($wholeonly)) $_SESSION["wholeonly"] = $wholeonly;
ocilogoff($conn);
?>
<table class="bd" width="100%"><tr><td class="hr">My Contacts</td></tr></table>
</body>
</html>
<?php function select()
{
global $a;
global $showrecs;
global $page;
global $filter;
global $filterfield;
global $wholeonly;
global $order;
global $ordtype;
if ($a == "reset") {
$filter = "";
$filterfield = "";
$wholeonly = "";
$order = "";
$ordtype = "";
}
$checkstr = "";
if ($wholeonly) $checkstr = " checked";
if ($ordtype == "asc") { $ordtypestr = "desc"; } else { $ordtypestr = "asc"; }
$res = sql_select();
$count = sql_getrecordcount();
if ($count % $showrecs != 0) {
$pagecount = intval($count / $showrecs) + 1;
}
else {
$pagecount = intval($count / $showrecs);
}
$startrec = $showrecs * ($page - 1);
if ($startrec < $count) {for ($i = 1; $i <= $startrec; ocifetchassoc($res), $i++);}
$reccount = min($showrecs * $page, $count);
$fields = array(
"NAME" => "NAME",
"CELLNO" => "CELLNO",
"DESIGNATION" => "DESIGNATION",
"OFFICE" => "OFFICE",
"EMAILID" => "EMAILID",
"ADDRESS" => "ADDRESS",
"REMARKS" => "REMARKS");
?>
<div style="float: right"><a href="contacts.php?a=logou
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr><td>Records shown <?php echo $startrec + 1 ?> - <?php echo $reccount ?> of <?php echo $count ?></td></tr>
</table>
<form action="contacts.php" method="post">
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><b>Custom Filter</b> </td>
<td><input type="text" name="filter" value="<?php echo $filter ?>"></td>
<td><select name="filter_field">
<option value="">All Fields</option>
<?php
reset($fields);
foreach($fields as $val => $caption) {
if ($val == $filterfield) {$selstr = " selected"; } else {$selstr = ""; }
?>
<option value="<?php echo $val ?>"<?php echo $selstr ?>><?php echo htmlspecialchars($caption)
<?php } ?>
</select></td>
<td><input type="checkbox" name="wholeonly"<?php echo $checkstr ?>>Whole words only</td>
</td></tr>
<tr>
<td> </td>
<td><input type="submit" name="action" value="Apply Filter"></td>
<td><a href="contacts.php?a=reset
</tr>
</table>
</form>
<?php showpagenav($page, $pagecount); ?>
<br>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="100%
<tr>
<?php
reset($fields);
foreach($fields as $val => $caption) {
?>
<td class="hr"><a class="hr" href="contacts.php?order=<?
<?php } ?>
<td class="hr"> </td>
<td class="hr"> </td>
<td class="hr"> </td>
</tr>
<?php
for ($i = $startrec; $i < $reccount; $i++)
{
$row = ocifetchassoc($res);
$style = "dr";
if ($i % 2 != 0) {
$style = "sr";
}
?>
<tr>
<?php
reset($fields);
foreach($fields as $val => $caption) {
?>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row[$val
<?php } ?>
<td class="<?php echo $style ?>"><a href="contacts.php?a=view&
<td class="<?php echo $style ?>"><a href="contacts.php?a=edit&
<td class="<?php echo $style ?>"><a href="contacts.php?a=del&r
</tr>
<?php
}
ocifreestatement($res);
?>
</table>
<br>
<?php showpagenav($page, $pagecount); ?>
<?php } ?>
<?php function login()
{
global $_POST;
global $_SESSION;
global $_GET;
if (isset($_GET["a"]) && ($_GET["a"] == 'logout')) $_SESSION["logged_in"] = false;
if (!isset($_SESSION["logged_
if (!$_SESSION["logged_in"]) {
$login = "";
$password = "";
if (isset($_POST["login"])) $login = @$_POST["login"];
if (isset($_POST["password"])
if (($login != "") && ($password != "")) {
if (($login == "ppc") && ($password == "ppc")) {
$_SESSION["logged_in"] = true;
}
else {
?>
<p><b><font color="-1">Sorry, the login/password combination you've entered is invalid</font></b></p>
<?php } } }if (isset($_SESSION["logged_i
<form action="contacts.php" method="post">
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td>Login</td>
<td><input type="text" name="login" value="<?php echo $login ?>"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" value="<?php echo $password ?>"></td>
</tr>
<tr>
<td><input type="submit" name="action" value="Login"></td>
</tr>
</table>
</form>
<?php
}
if (!isset($_SESSION["logged_
return $_SESSION["logged_in"];
} ?>
<?php function showrow($row)
{
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%"
<tr>
<td class="hr"><?php echo htmlspecialchars("NAME")."
<td class="dr"><?php echo htmlspecialchars($row["NAM
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("CELLNO")
<td class="dr"><?php echo htmlspecialchars($row["CEL
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("DESIGNAT
<td class="dr"><?php echo htmlspecialchars($row["DES
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("OFFICE")
<td class="dr"><?php echo htmlspecialchars($row["OFF
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("EMAILID"
<td class="dr"><?php echo htmlspecialchars($row["EMA
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("ADDRESS"
<td class="dr"><?php echo htmlspecialchars($row["ADD
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("REMARKS"
<td class="dr"><?php echo htmlspecialchars($row["REM
</tr>
</table>
<?php } ?>
<?php function showroweditor($row)
{
global $conn;
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="60%"
<tr>
<td class="hr"><?php echo htmlspecialchars("NAME")."
<td class="dr"><input type="text" name="NAME" maxlength="25" value="<?php echo str_replace('"', '"', trim($row["NAME"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("CELLNO")
<td class="dr"><input type="text" name="CELLNO" maxlength="25" value="<?php echo str_replace('"', '"', trim($row["CELLNO"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("DESIGNAT
<td class="dr"><input type="text" name="DESIGNATION" maxlength="25" value="<?php echo str_replace('"', '"', trim($row["DESIGNATION"]))
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("OFFICE")
<td class="dr"><input type="text" name="OFFICE" maxlength="25" value="<?php echo str_replace('"', '"', trim($row["OFFICE"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("EMAILID"
<td class="dr"><input type="text" name="EMAILID" maxlength="30" value="<?php echo str_replace('"', '"', trim($row["EMAILID"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("ADDRESS"
<td class="dr"><input type="text" name="ADDRESS" maxlength="50" value="<?php echo str_replace('"', '"', trim($row["ADDRESS"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("REMARKS"
<td class="dr"><input type="text" name="REMARKS" maxlength="10" value="<?php echo str_replace('"', '"', trim($row["REMARKS"])) ?>"></td>
</tr>
</table>
<?php } ?>
<?php function showpagenav($page, $pagecount)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="contacts.php?a=add">A
<?php if ($page > 1) { ?>
<td><a href="contacts.php?page=<?p
<?php } ?>
<?php
global $pagerange;
if ($pagecount > 1) {
if ($pagecount % $pagerange != 0) {
$rangecount = intval($pagecount / $pagerange) + 1;
}
else {
$rangecount = intval($pagecount / $pagerange);
}
for ($i = 1; $i < $rangecount + 1; $i++) {
$startpage = (($i - 1) * $pagerange) + 1;
$count = min($i * $pagerange, $pagecount);
if ((($page >= $startpage) && ($page <= ($i * $pagerange)))) {
for ($j = $startpage; $j < $count + 1; $j++) {
if ($j == $page) {
?>
<td><b><?php echo $j ?></b></td>
<?php } else { ?>
<td><a href="contacts.php?page=<?p
<?php } } } else { ?>
<td><a href="contacts.php?page=<?p
<?php } } } ?>
<?php if ($page < $pagecount) { ?>
<td> <a href="contacts.php?page=<?p
<?php } ?>
</tr>
</table>
<?php } ?>
<?php function showrecnav($a, $recid, $count)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="contacts.php">Index Page</a></td>
<?php if ($recid > 0) { ?>
<td><a href="contacts.php?a=<?php echo $a ?>&recid=<?php echo $recid - 1 ?>">Prior Record</a></td>
<?php } if ($recid < $count - 1) { ?>
<td><a href="contacts.php?a=<?php echo $a ?>&recid=<?php echo $recid + 1 ?>">Next Record</a></td>
<?php } ?>
</tr>
</table>
<hr size="1" noshade>
<?php } ?>
<?php function addrec()
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="contacts.php">Index Page</a></td>
</tr>
</table>
<hr size="1" noshade>
<form action="contacts.php" method="post">
<p><input type="hidden" name="sql" value="insert"></p>
<?php
$row = array(
"NAME" => "",
"CELLNO" => "",
"DESIGNATION" => "",
"OFFICE" => "",
"EMAILID" => "",
"ADDRESS" => "",
"REMARKS" => "");
showroweditor($row)
?>
<p><input type="submit" name="action" value="Post"></p>
</form>
<?php } ?>
<?php function viewrec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
for ($i = 1; $i <= $recid; ocifetchassoc($res), $i++);
$row = ocifetchassoc($res);
showrecnav("view", $recid, $count);
?>
<br>
<?php showrow($row) ?>
<br>
<hr size="1" noshade>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="contacts.php?a=add">A
<td><a href="contacts.php?a=edit&
<td><a href="contacts.php?a=del&r
</tr>
</table>
<?php
ocifreestatement($res);
} ?>
<?php function editrec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
for ($i = 1; $i <= $recid; ocifetchassoc($res), $i++);
$row = ocifetchassoc($res);
showrecnav("edit", $recid, $count);
?>
<br>
<form action="contacts.php" method="post">
<input type="hidden" name="sql" value="update">
<input type="hidden" name="xNAME" value="<?php echo $row["NAME"] ?>">
<input type="hidden" name="xCELLNO" value="<?php echo $row["CELLNO"] ?>">
<input type="hidden" name="xDESIGNATION" value="<?php echo $row["DESIGNATION"] ?>">
<input type="hidden" name="xOFFICE" value="<?php echo $row["OFFICE"] ?>">
<input type="hidden" name="xEMAILID" value="<?php echo $row["EMAILID"] ?>">
<input type="hidden" name="xADDRESS" value="<?php echo $row["ADDRESS"] ?>">
<input type="hidden" name="xREMARKS" value="<?php echo $row["REMARKS"] ?>">
<?php showroweditor($row) ?>
<p><input type="submit" name="action" value="Post"></p>
</form>
<?php
ocifreestatement($res);
} ?>
<?php function deleterec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
for ($i = 1; $i <= $recid; ocifetchassoc($res), $i++);
$row = ocifetchassoc($res);
showrecnav("del", $recid, $count);
?>
<br>
<form action="contacts.php" method="post">
<input type="hidden" name="sql" value="delete">
<input type="hidden" name="xNAME" value="<?php echo $row["NAME"] ?>">
<input type="hidden" name="xCELLNO" value="<?php echo $row["CELLNO"] ?>">
<input type="hidden" name="xDESIGNATION" value="<?php echo $row["DESIGNATION"] ?>">
<input type="hidden" name="xOFFICE" value="<?php echo $row["OFFICE"] ?>">
<input type="hidden" name="xEMAILID" value="<?php echo $row["EMAILID"] ?>">
<input type="hidden" name="xADDRESS" value="<?php echo $row["ADDRESS"] ?>">
<input type="hidden" name="xREMARKS" value="<?php echo $row["REMARKS"] ?>">
<?php showrow($row) ?>
<p><input type="submit" name="action" value="Confirm"></p>
</form>
<?php
ocifreestatement($res);
} ?>
<?php function connect()
{
$conn = ocilogon("PPC", "ppc123", "payroll");
return $conn;
}
function sqlvalue($val, $quote)
{
if ($quote)
$tmp = sqlstr($val);
else
$tmp = $val;
if ($tmp == "")
$tmp = "NULL";
elseif ($quote)
$tmp = "'".$tmp."'";
return $tmp;
}
function sqlstr($val)
{
return str_replace("'", "''", $val);
}
function sql_select()
{
global $conn;
global $order;
global $ordtype;
global $filter;
global $filterfield;
global $wholeonly;
$filterstr = sqlstr($filter);
if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
$sql = "SELECT \"NAME\", CELLNO, DESIGNATION, OFFICE, EMAILID, ADDRESS, REMARKS FROM PPC.TBL_CONTACTS";
if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
$sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
} elseif (isset($filterstr) && $filterstr!='') {
$sql .= " where (\"NAME\" like '" .$filterstr ."') or (CELLNO like '" .$filterstr ."') or (DESIGNATION like '" .$filterstr ."') or (OFFICE like '" .$filterstr ."') or (EMAILID like '" .$filterstr ."') or (ADDRESS like '" .$filterstr ."') or (REMARKS like '" .$filterstr ."')";
}
if (isset($order) && $order!='') $sql .= " order by \"" .sqlstr($order) ."\"";
if (isset($ordtype) && $ordtype!='') $sql .= " " .sqlstr($ordtype);
$res = ociquery($sql);
return $res;
}
function sql_getrecordcount()
{
global $conn;
global $order;
global $ordtype;
global $filter;
global $filterfield;
global $wholeonly;
$filterstr = sqlstr($filter);
if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
$sql = "SELECT COUNT(*) FROM PPC.TBL_CONTACTS";
if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
$sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
} elseif (isset($filterstr) && $filterstr!='') {
$sql .= " where (\"NAME\" like '" .$filterstr ."') or (CELLNO like '" .$filterstr ."') or (DESIGNATION like '" .$filterstr ."') or (OFFICE like '" .$filterstr ."') or (EMAILID like '" .$filterstr ."') or (ADDRESS like '" .$filterstr ."') or (REMARKS like '" .$filterstr ."')";
}
$res = ociquery($sql);
$row = ocifetchassoc($res);
reset($row);
return current($row);
}
function sql_insert()
{
global $conn;
global $_POST;
$sql = "insert into PPC.TBL_CONTACTS (\"NAME\", CELLNO, DESIGNATION, OFFICE, EMAILID, ADDRESS, REMARKS) values (" .sqlvalue(@$_POST["NAME"],
ociquery($sql);
}
function sql_update()
{
global $conn;
global $_POST;
$sql = "update PPC.TBL_CONTACTS set \"NAME\"=" .sqlvalue(@$_POST["NAME"],
ociquery($sql);
}
function sql_delete()
{
global $conn;
$sql = "delete from PPC.TBL_CONTACTS where " .primarykeycondition();
ociquery($sql);
}
function primarykeycondition()
{
global $_POST;
$pk = "";
$pk .= "(\"NAME\"";
if (@$_POST["xNAME"] == "") {
$pk .= " IS NULL";
}else{
$pk .= " = " .sqlvalue(@$_POST["xNAME"]
};
$pk .= ") and ";
$pk .= "(CELLNO";
if (@$_POST["xCELLNO"] == "") {
$pk .= " IS NULL";
}else{
$pk .= " = " .sqlvalue(@$_POST["xCELLNO
};
$pk .= ") and ";
$pk .= "(DESIGNATION";
if (@$_POST["xDESIGNATION"] == "") {
$pk .= " IS NULL";
}else{
$pk .= " = " .sqlvalue(@$_POST["xDESIGN
};
$pk .= ") and ";
$pk .= "(OFFICE";
if (@$_POST["xOFFICE"] == "") {
$pk .= " IS NULL";
}else{
$pk .= " = " .sqlvalue(@$_POST["xOFFICE
};
$pk .= ") and ";
$pk .= "(EMAILID";
if (@$_POST["xEMAILID"] == "") {
$pk .= " IS NULL";
}else{
$pk .= " = " .sqlvalue(@$_POST["xEMAILI
};
$pk .= ") and ";
$pk .= "(ADDRESS";
if (@$_POST["xADDRESS"] == "") {
$pk .= " IS NULL";
}else{
$pk .= " = " .sqlvalue(@$_POST["xADDRES
};
$pk .= ") and ";
$pk .= "(REMARKS";
if (@$_POST["xREMARKS"] == "") {
$pk .= " IS NULL";
}else{
$pk .= " = " .sqlvalue(@$_POST["xREMARK
};
$pk .= ")";
return $pk;
}
function ociquery($sql)
{
global $conn;
$res = ociparse($conn, $sql);
ociexecute($res, OCI_DEFAULT) or die(ocierror());
ocicommit($conn);
return $res;
}
function ocifetchassoc($res)
{
$ret_array = array();
ocifetchinto($res, $ret_array, OCI_ASSOC);
return $ret_array;
} ?>
Main Topics
Browse All Topics





by: routinetPosted on 2009-10-30 at 22:58:55ID: 25708658
http://www.phpmyadmin.net/ home_page/ index.php