OK Here is my code
Patient.php calls searchbyssn() in classpatient.inc..
This calls dbopen and db query in db.inc that is where things fall apart..
----------------------- code from 3 files -----------------------
classpatient.inc
<?php
include "db.inc"; // database constants..
include "classperson.inc";
class patient extends person
{
var $insurer;
var $employer;
var $workphone;
var $garrentar; // parent or bill payer.
function save()
{
echo("saving patient $this->lastname");
dbopen();
$sql = "Insert into patient (firstname,lastname,address,city,state,zip,phone,dob,ssn,insurer,employer,workphone)
values ('$this->firstname', '$this->lastname', '$this->address', '$this->city', '$this->state', '$this->zip', '$this->phone', '$this->dob', '$this->ssn', '$this->insurer', '$this->employer', '$this->workphone' )";
return dbquery( $sql );
}
function searchbyname()
{
dbopen();
$sql = "select * from patient where lastname = '$this->lastname'";
// should probably populate the object with the data if there is just one..
return dbquery( $sql );
}
function searchbyssn()
{
//global dbopen(), dbquery();
echo("in searchbyssn<br>");
$sql = "select * from patient where ssn = '$this->ssn'";
echo("$sql<br>");
echo("getting patient with ssn<br>");
// should probably populate the object with the data if there is just one..
$result = dbquery( $sql );
/ $numrows = mysql_num_rows($result);
if($numrows)
{
$this->firstname = mysql_result($result,0,"firstname");
}
else echo("more than 1 record..<br>");
/
return;
}
}
?>
db.inc
<?php
$db = "";
$host = "localhost";
$user = "root";
$pass = "root";
$dbname = "savantmed";
$result = 0;
$errno = 0;
$errstr "";
print("db.inc included..");
function dbquery( $sql )
{
global $db,$result, $errno, $errstr;
echo("in dbquery");
$result = mysql_query("$sql",$db);
// add some error checking here..
if( !$result )
{
// we had a problem..
echo mysql_errno().": ".mysql_error()."<BR>";
return 0;
}
return $result;
}
function dbopen()
{
global $db, $host, $user, $pass, $dbname, $errno, $errstr;
echo("in dbopen");
echo("user = $user");
$db = mysql_connect( "$host", "$user", "$pass");
if(!mysql_select_db("$dbname",$db))
{
// we had a problem..
$errno = mysql_errno();
$errstr = mysql_error();
echo mysql_errno().": ".mysql_error()."<BR>";
return 0;
}
echo("dbopen..");
return 1;
}
function dbclose()
{
mysql_close($db);
$db = 0;
return;
}
?>
patient.php
<?php
$pgtitle = "Patient Management";
$search=$HTTP_POST_VARS["search"];
$add=$HTTP_POST_VARS["add"];
$save = $HTTP_POST_VARS["save"];
$firstname = $HTTP_POST_VARS["fname"];
$lastname = $HTTP_POST_VARS["lname"];
$address = $HTTP_POST_VARS["address"];
$city = $HTTP_POST_VARS{"city"};
$state = $HTTP_POST_VARS["state"];
$zip = $HTTP_POST_VARS["zip"];
$phone = $HTTP_POST_VARS["phone"];
$dob = $HTTP_POST_VARS["dob"];
$employer = $HTTP_POST_VARS["employer"];
$garrentar = $HTTP_POST_VARS["garrentar"];
$insurer = $HTTP_POST_VARS["insurer"];
$ssn = $HTTP_POST_VARS["ssn"];
$workphone = $HTTP_POST_VARS["workphone"];
$page = $PHP_SELF;
include"config.php";
include"classpatient.inc";
include"navbar.php";
function pform()
{
global $page;
print"<div align=\"center\">
<table width=\"95%\" border=\"1\">
<tr>
<td>
<table>
<form action=";
echo("$page");
print" method=\"post\">
<tr><td>Name: First</td><td><input type=\"text\" name=\"fname\" value=".$p->firstname."> </td><td>Last</td><td><input type=\"text\" name=\"lname\" value=".$p->lastname." ></td></tr>
<tr><td>Address</td><td><input type=\"text\" name=\"address\" value=".$p->address." ></td><td>City</td><td><input type=\"text\" name=\"city\" value=".$p->city." ></td></tr>
<tr><td>State</td><td><input type=\"text\" name=\"state\" value=".$p->state." ></td><td>Zip</td><td><input type=\"text\" name=\"zip\" value=".$p->zip." ></td></tr>
<tr><td>Phone</td><td><input type=\"text\" name=\"phone\" value=".$p->phone." ></td></tr>
<tr><td>DOB</td><td><input type=\"text\" name=\"dob\" value=".$p->dob." ></td><td>SSN</td><td><input type=\"text\" name=\"ssn\" value=".$p->ssn." ></td></tr>
<tr><td colspan=\"4\"><hr></td></tr>
<tr><td>Insurer</td><td><input type=\"text\" name=\"insurer\" value=".$p->insurer." ></td><td>Garrentar</td><td><input type=\"text\" name=\"garrentar\" value=".$p->garrentar." ></td></tr>
<tr><td>Employer</td><td><input type=\"text\" name=\"employer\" value=".$p->employer." ></td><td>Work Phone</td><td><input type=\"text\" name=\"workphone\" value=".$p->workphone." ></td></tr>
<tr><td colspan=\"4\"><hr></td></tr>
<tr><td><input type=\"submit\" name=\"search\" id=\"search\" value=\"search\">
</td><td>
<input type=\"submit\" name=\"add\" id=\"add\" value=\"add\">
</td><td>
<input type=\"submit\" name=\"save\" id=\"save\" value=\"save\">
</td></tr>
</form>
</table>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</div>
</body>
</html>";
return;
}
echo"search=$search add=$add save=$save ssn=$ssn";
if($add=="add" || $save=="save") // adding or saving an edited patient..
{
$p = new patient();
$p->firstname = $firstname;
$p->lastname = $lastname;
$p->address = $address;
$p->city = $city;
$p->state = $state;
$p->zip = $zip;
$p->phone = $phone;
$p->dob = $dob;
$p->employer = $employer;
$p->garrentar = $garrentar;
$p->insurer = $insurer;
$p->ssn = $ssn;
$p->workphone = $workphone;
$p->save();
echo"Patient record saved";
}
else if($search=="search")
{
$p = new patient();
$p->firstname = $firstname;
$p->lastname = $lastname;
$p->ssn = $ssn;
if($p->lastname != "")
{
$p->searchbyname(); // need to process case where more than one record returned.
// should probably put the names into a pull down and allow selections..
}
else if($p->ssn != "")
{
echo("$p->ssn<br>");
$p->searchbyssn();
}
echo("Search results");
}
// do this last..
htmlhead();
navbar();
pform();
?>