I need help with using php to dislplay data from a firebird database. I've tried various methods but no success so far. My latest attempt has been to try PHP Generator. I get indications that it should work, but it falls short of displaying the data. Here is a sample php script I've tried:
<?php session_start();
if (isset($_GET["order"])) $order = @$_GET["order"];
if (isset($_GET["type"])) $ordtype = @$_GET["type"];
if (!isset($order) && isset($_SESSION["order"])) $order = $_SESSION["order"];
if (!isset($ordtype) && isset($_SESSION["type"])) $ordtype = $_SESSION["type"];
?>
<html>
<head>
<title>D:\My Documents\Mike\Chemical2\Chem2009\CHEMICAL03.GDB -- INFO</title>
<meta name="generator" http-equiv="content-type" content="text/html">
<style type="text/css">
body {
background-color: #317676;
color: #FFFFFF;
font-family: Arial;
font-size: 12px;
}
.bd {
background-color: #317676;
color: #FFFFFF;
font-family: Arial;
font-size: 12px;
}
.tbl {
background-color: #276262;
}
a:link {
color: #FFE760;
font-family: Arial;
font-size: 12px;
}
a:active {
color: #FFFF00;
font-family: Arial;
font-size: 12px;
}
a:visited {
color: #CCCC39;
font-family: Arial;
font-size: 12px;
}
.hr {
background-color: #3A9393;
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: #276262;
color: #FFE760;
font-family: Arial;
font-size: 12px;
}
.sr {
background-color: #367800;
color: #FFE760;
font-family: Arial;
font-size: 12px;
}
</style>
</head>
<body>
<table class="bd" width="100%"><tr><td class="hr"><h2>PHP Generator</h2></td></tr></table>
<?php
if (!login()) exit;
?>
<div style="float: right"><a href="INFO.php?a=logout">[ Logout ]</a></div>
<br>
<?php
$conn = connect();
$showrecs = 20;
$pagerange = 10;
$a = @$_GET["a"];
$recid = @$_GET["recid"];
$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;
ibase_close($conn);
?>
<table class="bd" width="100%"><tr><td class="hr">http://www.sqlmaestro.com/products/firebird/phpgenerator/</td></tr></table>
</body>
</html>
<?php function select()
{
global $a;
global $showrecs;
global $page;
global $order;
global $ordtype;
if ($a == "reset") {
$order = "";
$ordtype = "";
}
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; ibase_fetch_assoc($res), $i++);}
$reccount = min($showrecs * $page, $count);
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr><td>Table: INFO</td></tr>
<tr><td>Records shown <?php echo $startrec + 1 ?> - <?php echo $reccount ?> of <?php echo $count ?></td></tr>
</table>
<hr size="1" noshade>
<?php showpagenav($page, $pagecount); ?>
<br>
<table class="tbl" border="5" cellspacing="6" cellpadding="10"width="100%">
<tr>
<td class="hr"> </td>
<td class="hr"> </td>
<td class="hr"> </td>
<td class="hr"><a class="hr" href="INFO.php?order=<?php echo "CAS" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("CAS") ?></a></td>
<td class="hr"><a class="hr" href="INFO.php?order=<?php echo "FORMULA" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("FORMULA") ?></a></td>
<td class="hr"><a class="hr" href="INFO.php?order=<?php echo "STRUCTURE" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("STRUCTURE") ?></a></td>
<td class="hr"><a class="hr" href="INFO.php?order=<?php echo "FW" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("FW") ?></a></td>
<td class="hr"><a class="hr" href="INFO.php?order=<?php echo "DENSITY" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("DENSITY") ?></a></td>
<td class="hr"><a class="hr" href="INFO.php?order=<?php echo "RI" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("RI") ?></a></td>
<td class="hr"><a class="hr" href="INFO.php?order=<?php echo "SOLUBILITY" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("SOLUBILITY") ?></a></td>
<td class="hr"><a class="hr" href="INFO.php?order=<?php echo "ORGANIC" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("ORGANIC") ?></a></td>
<td class="hr"><a class="hr" href="INFO.php?order=<?php echo "OTHER" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("OTHER") ?></a></td>
<td class="hr"><a class="hr" href="INFO.php?order=<?php echo "MP" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("MP") ?></a></td>
<td class="hr"><a class="hr" href="INFO.php?order=<?php echo "BP" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("BP") ?></a></td>
<td class="hr"><a class="hr" href="INFO.php?order=<?php echo "PKA1" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("PKA1") ?></a></td>
<td class="hr"><a class="hr" href="INFO.php?order=<?php echo "PKA2" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("PKA2") ?></a></td>
<td class="hr"><a class="hr" href="INFO.php?order=<?php echo "PKA3" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("PKA3") ?></a></td>
<td class="hr"><a class="hr" href="INFO.php?order=<?php echo "PKA4" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("PKA4") ?></a></td>
</tr>
<?php
for ($i = $startrec; $i < $reccount; $i++)
{
$row = ibase_fetch_assoc($res);
$style = "dr";
if ($i % 2 != 0) {
$style = "sr";
}
?>
<tr>
<td class="<?php echo $style ?>"><a href="INFO.php?a=view&recid=<?php echo $i ?>">View</a></td>
<td class="<?php echo $style ?>"><a href="INFO.php?a=edit&recid=<?php echo $i ?>">Edit</a></td>
<td class="<?php echo $style ?>"><a href="INFO.php?a=del&recid=<?php echo $i ?>">Delete</a></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["CAS"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["FORMULA"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["STRUCTURE"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["FW"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["DENSITY"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["RI"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["SOLUBILITY"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["ORGANIC"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["OTHER"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["MP"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["BP"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["PKA1"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["PKA2"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["PKA3"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["PKA4"]) ?></td>
</tr>
<?php
}
ibase_free_result($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_in"])) $_SESSION["logged_in"] = false;
if (!$_SESSION["logged_in"]) {
$login = "";
$password = "";
if (isset($_POST["login"])) $login = @$_POST["login"];
if (isset($_POST["password"])) $password = @$_POST["password"];
if (($login != "") && ($password != "")) {
if (($login == "sysdba") && ($password == "liteman5")) {
$_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_in"]) && (!$_SESSION["logged_in"])) { ?>
<form action="INFO.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_in"])) $_SESSION["logged_in"] = false;
return $_SESSION["logged_in"];
} ?>
<?php function showrow($row, $recid)
{
?>
<table class="tbl" border="5" cellspacing="6" cellpadding="10"width="50%">
<tr>
<td class="hr"><?php echo htmlspecialchars("CAS")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["CAS"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("FORMULA")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["FORMULA"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("STRUCTURE")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["STRUCTURE"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("FW")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["FW"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("DENSITY")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["DENSITY"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("RI")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["RI"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("SOLUBILITY")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["SOLUBILITY"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("ORGANIC")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["ORGANIC"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("OTHER")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["OTHER"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("MP")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["MP"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("BP")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["BP"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("PKA1")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["PKA1"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("PKA2")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["PKA2"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("PKA3")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["PKA3"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("PKA4")." " ?></td>
<td class="dr"><?php echo htmlspecialchars($row["PKA4"]) ?></td>
</tr>
</table>
<?php } ?>
<?php function showroweditor($row, $iseditmode)
{
global $conn;
?>
<table class="tbl" border="5" cellspacing="6" cellpadding="10"width="50%">
<tr>
<td class="hr"><?php echo htmlspecialchars("CAS")." " ?></td>
<td class="dr"><input type="text" name="CAS" maxlength="15" value="<?php echo str_replace('"', '"', trim($row["CAS"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("FORMULA")." " ?></td>
<td class="dr"><textarea cols="35" rows="4" name="FORMULA" maxlength="80"><?php echo str_replace('"', '"', trim($row["FORMULA"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("STRUCTURE")." " ?></td>
<td class="dr"><textarea cols="35" rows="4" name="STRUCTURE" maxlength="155"><?php echo str_replace('"', '"', trim($row["STRUCTURE"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("FW")." " ?></td>
<td class="dr"><input type="text" name="FW" value="<?php echo str_replace('"', '"', trim($row["FW"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("DENSITY")." " ?></td>
<td class="dr"><input type="text" name="DENSITY" value="<?php echo str_replace('"', '"', trim($row["DENSITY"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("RI")." " ?></td>
<td class="dr"><input type="text" name="RI" value="<?php echo str_replace('"', '"', trim($row["RI"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("SOLUBILITY")." " ?></td>
<td class="dr"><input type="text" name="SOLUBILITY" maxlength="40" value="<?php echo str_replace('"', '"', trim($row["SOLUBILITY"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("ORGANIC")." " ?></td>
<td class="dr"><input type="text" name="ORGANIC" value="<?php echo str_replace('"', '"', trim($row["ORGANIC"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("OTHER")." " ?></td>
<td class="dr"><textarea cols="35" rows="4" name="OTHER" maxlength="100"><?php echo str_replace('"', '"', trim($row["OTHER"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("MP")." " ?></td>
<td class="dr"><input type="text" name="MP" value="<?php echo str_replace('"', '"', trim($row["MP"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("BP")." " ?></td>
<td class="dr"><input type="text" name="BP" value="<?php echo str_replace('"', '"', trim($row["BP"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("PKA1")." " ?></td>
<td class="dr"><input type="text" name="PKA1" value="<?php echo str_replace('"', '"', trim($row["PKA1"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("PKA2")." " ?></td>
<td class="dr"><input type="text" name="PKA2" value="<?php echo str_replace('"', '"', trim($row["PKA2"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("PKA3")." " ?></td>
<td class="dr"><input type="text" name="PKA3" value="<?php echo str_replace('"', '"', trim($row["PKA3"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("PKA4")." " ?></td>
<td class="dr"><input type="text" name="PKA4" value="<?php echo str_replace('"', '"', trim($row["PKA4"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("STRUCT2")." " ?></td>
<td class="dr">
<?php if ($iseditmode)
{
?> <input type="radio" name="a_STRUCT2" id="a_STRUCT2" value="1" checked>Keep
<input type="radio" name="a_STRUCT2" id="a_STRUCT2" value="2">Remove
<input type="radio" name="a_STRUCT2" id="a_STRUCT2" value="3">Replace<br>
<?php }
?> <input type="file" name="x_STRUCT2" id="x_STRUCT2" size="30" onchange="if (this.form.a_STRUCT2[2]) this.form.a_STRUCT2[2].checked=true;" >
</td>
</tr>
</table>
<?php } ?>
<?php function showpagenav($page, $pagecount)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="INFO.php?a=add">Add Record</a> </td>
<?php if ($page > 1) { ?>
<td><a href="INFO.php?page=<?php echo $page - 1 ?>"><< Prev</a> </td>
<?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="INFO.php?page=<?php echo $j ?>"><?php echo $j ?></a></td>
<?php } } } else { ?>
<td><a href="INFO.php?page=<?php echo $startpage ?>"><?php echo $startpage ."..." .$count ?></a></td>
<?php } } } ?>
<?php if ($page < $pagecount) { ?>
<td> <a href="INFO.php?page=<?php echo $page + 1 ?>">Next >></a> </td>
<?php } ?>
</tr>
</table>
<?php } ?>
<?php function showrecnav($a, $recid, $count)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="INFO.php">Index Page</a></td>
<?php if ($recid > 0) { ?>
<td><a href="INFO.php?a=<?php echo $a ?>&recid=<?php echo $recid - 1 ?>">Prior Record</a></td>
<?php } if ($recid < $count - 1) { ?>
<td><a href="INFO.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="INFO.php">Index Page</a></td>
</tr>
</table>
<hr size="1" noshade>
<form enctype="multipart/form-data" action="INFO.php" method="post">
<p><input type="hidden" name="sql" value="insert"></p>
<?php
$row = array(
"CAS" => "",
"FORMULA" => "",
"STRUCTURE" => "",
"FW" => "",
"DENSITY" => "",
"RI" => "",
"SOLUBILITY" => "",
"ORGANIC" => "",
"OTHER" => "",
"MP" => "",
"BP" => "",
"PKA1" => "",
"PKA2" => "",
"PKA3" => "",
"PKA4" => "");
showroweditor($row, false);
?>
<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; ibase_fetch_assoc($res), $i++);
$row = ibase_fetch_assoc($res);
showrecnav("view", $recid, $count);
?>
<br>
<?php showrow($row, $recid) ?>
<br>
<hr size="1" noshade>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="INFO.php?a=add">Add Record</a></td>
<td><a href="INFO.php?a=edit&recid=<?php echo $recid ?>">Edit Record</a></td>
<td><a href="INFO.php?a=del&recid=<?php echo $recid ?>">Delete Record</a></td>
</tr>
</table>
<?php
ibase_free_result($res);
} ?>
<?php function editrec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
for ($i = 1; $i <= $recid; ibase_fetch_assoc($res), $i++);
$row = ibase_fetch_assoc($res);
showrecnav("edit", $recid, $count);
?>
<br>
<form enctype="multipart/form-data" action="INFO.php" method="post">
<input type="hidden" name="sql" value="update">
<input type="hidden" name="xCAS" value="<?php echo $row["CAS"] ?>">
<?php showroweditor($row, true); ?>
<p><input type="submit" name="action" value="Post"></p>
</form>
<?php
ibase_free_result($res);
} ?>
<?php function deleterec($recid)
{
$res = sql_select();
$count = sql_getrecordcount();
for ($i = 1; $i <= $recid; ibase_fetch_assoc($res), $i++);
$row = ibase_fetch_assoc($res);
showrecnav("del", $recid, $count);
?>
<br>
<form action="INFO.php" method="post">
<input type="hidden" name="sql" value="delete">
<input type="hidden" name="xCAS" value="<?php echo $row["CAS"] ?>">
<?php showrow($row, $recid) ?>
<p><input type="submit" name="action" value="Confirm"></p>
</form>
<?php
ibase_free_result($res);
} ?>
<?php function connect()
{
$conn = ibase_connect("localhost:D:/My Documents/Mike/Chemical2/Chem2009/CHEMICAL03.GDB", "SYSDBA", "liteman5");
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;
$sql = "SELECT CAS, FORMULA, STRUCTURE, FW, DENSITY, RI, SOLUBILITY, ORGANIC, OTHER, MP, BP, PKA1, PKA2, PKA3, PKA4, STRUCT2 FROM INFO";
if (isset($order) && $order!='') $sql .= " order by \"" .sqlstr($order) ."\"";
if (isset($ordtype) && $ordtype!='') $sql .= " " .sqlstr($ordtype);
$res = ibase_query($conn, $sql) or die(ibase_errcode());
return $res;
}
function sql_getrecordcount()
{
global $conn;
global $order;
global $ordtype;
$sql = "SELECT COUNT(*) FROM INFO";
$res = ibase_query($conn, $sql) or die(ibase_errcode());
$row = ibase_fetch_assoc($res);
reset($row);
return current($row);
}
function sql_insert()
{
global $conn;
global $_POST;
$sql = "insert into INFO (CAS, FORMULA, STRUCTURE, FW, DENSITY, RI, SOLUBILITY, ORGANIC, OTHER, MP, BP, PKA1, PKA2, PKA3, PKA4, STRUCT2) values (" .sqlvalue(@$_POST["CAS"], true).", " .sqlvalue(@$_POST["FORMULA"], true).", " .sqlvalue(@$_POST["STRUCTURE"], true).", " .sqlvalue(@$_POST["FW"], false).", " .sqlvalue(@$_POST["DENSITY"], false).", " .sqlvalue(@$_POST["RI"], false).", " .sqlvalue(@$_POST["SOLUBILITY"], true).", " .sqlvalue(@$_POST["ORGANIC"], false).", " .sqlvalue(@$_POST["OTHER"], true).", " .sqlvalue(@$_POST["MP"], false).", " .sqlvalue(@$_POST["BP"], false).", " .sqlvalue(@$_POST["PKA1"], false).", " .sqlvalue(@$_POST["PKA2"], false).", " .sqlvalue(@$_POST["PKA3"], false).", " .sqlvalue(@$_POST["PKA4"], false).", "."?".")";
ibase_query($conn, $sql, getblobfromfilecontent("STRUCT2")) or die(ibase_errcode());
}
function sql_update()
{
global $conn;
global $_POST;
$sql = "update INFO set CAS=" .sqlvalue(@$_POST["CAS"], true).", FORMULA=" .sqlvalue(@$_POST["FORMULA"], true).", STRUCTURE=" .sqlvalue(@$_POST["STRUCTURE"], true).", FW=" .sqlvalue(@$_POST["FW"], false).", DENSITY=" .sqlvalue(@$_POST["DENSITY"], false).", RI=" .sqlvalue(@$_POST["RI"], false).", SOLUBILITY=" .sqlvalue(@$_POST["SOLUBILITY"], true).", ORGANIC=" .sqlvalue(@$_POST["ORGANIC"], false).", OTHER=" .sqlvalue(@$_POST["OTHER"], true).", MP=" .sqlvalue(@$_POST["MP"], false).", BP=" .sqlvalue(@$_POST["BP"], false).", PKA1=" .sqlvalue(@$_POST["PKA1"], false).", PKA2=" .sqlvalue(@$_POST["PKA2"], false).", PKA3=" .sqlvalue(@$_POST["PKA3"], false).", PKA4=" .sqlvalue(@$_POST["PKA4"], false).", ".get_file_content_as_sql_for_update("STRUCT2") ." where " .primarykeycondition();
ibase_query($conn, $sql, getblobinfo("STRUCT2")) or die(ibase_errcode());
}
function sql_delete()
{
global $conn;
$sql = "delete from INFO where " .primarykeycondition();
ibase_query($conn, $sql) or die(ibase_errcode());
}
function primarykeycondition()
{
global $_POST;
$pk = "";
$pk .= "(CAS";
if (@$_POST["xCAS"] == "") {
$pk .= " IS NULL";
}else{
$pk .= " = " .sqlvalue(@$_POST["xCAS"], true);
};
$pk .= ")";
return $pk;
}
function get_file_content_as_sql($fieldname)
{
global $_FILES;
$sql = "";
if (!empty($_FILES))
$sql=file_get_contents(@$_FILES['x_'.$fieldname]['tmp_name']);
if ($sql == '')
$sql = 'null';
return $sql;
}
function get_file_content_as_sql_for_update($fieldname)
{
global $_POST;
$sql = "\"$fieldname\"=?";
if (isset($_POST["a_".$fieldname]))
{
switch ($_POST["a_".$fieldname]) {
//remove
case "2":
$sql = "\"$fieldname\"= NULL";
break;
};
}
return $sql;
}
function getblobfromfilecontent($fieldname)
{
global $conn;
$blh = ibase_blob_create($conn);
ibase_blob_add($blh, get_file_content_as_sql($fieldname));
return ibase_blob_close($blh);
}
function getblobinfo($fieldname)
{
global $conn;
global $_POST;
if (isset($_POST["a_".$fieldname]))
{
switch ($_POST["a_".$fieldname])
{
//replace
case "3":
return getblobfromfilecontent($fieldname);
break;
default:
$subsql="select $fieldname from INFO"." where " .primarykeycondition();
$res = ibase_query($conn, $subsql) or die(ibase_errcode());
$row = ibase_fetch_assoc($res);
return $row[$fieldname];
break;
}
}
}
?>
Can anybody give me anything new to try? Any help would be greatly appreciated.
Thanks