Jump to content

Archived

This topic is now archived and is closed to further replies.

Arl8

Trouble with ODBC Edit/Update records form

Recommended Posts

Hey all,

I am moderately familiar with PHP and have been using it for a couple years for various different things.

Basic information about my system:

PHP 5
MySQL 4.1
Apache
Windows XP Pro

I'm using PHP/MySQL for a web-based server and have an ODBC set up in my office.  I'm running into some problems using the ODBC code as opposed to the MySQL code in some scripts I have been writing.  **In my scripts I use an ODBC database converter found in a tutorial on phpfreaks here [url=http://www.phpfreaks.com/tutorials/61/2.php]http://www.phpfreaks.com/tutorials/61/2.php[/url] , contains connection string also.  Also using MySQL Query Builder for testing SQL syntax.


What i'm attempting to do at this point is make 3 scripts that allow me to input data specific to a patient, call the rest of the patient's information from my database, and update the additional information.  This first script makes a form where I input information patients at the office, Patient ID in this case.  This works fine, and after this form the form posts to my next script, displayrecord.php.  After inputing data, the script should call the particular record and display the rest of the information

**code to create the form that accepts the patient id and displays the record from the patient table

[code]
<p> </p>
<form name="updateform" method="post" action="displayrecord.php">
  <table width="250" border="0" align="center" cellpadding="3">
    <tr>
      <td colspan="2">
        <center><b>Enter Patient ID</b></center>
      </td>
    </tr>
    <tr >
      <td width="100">
        <center>Patient ID</center>
      </td>
      <td width="150">
        <input type="text" name="ptid">
      </td>
    </tr>
    <tr>
      <td colspan="2" >
        <center>
          <input type="submit" name="Submit" value="Submit">
        </center>
      </td>
    </tr>
<? require_once(odbc.php); ?>
[/code]

**PHP script to display the record and accept the updates for the existing record**  I run into problems as soon as I call displayrecord.php, i'm pretty sure my SQL syntax is correct, but it could be a problem with the form construction.  The output will show the beginning of the form, but no other fields of the form.  I feel it doesn't work because of naming/calling the fields from the array for the form inputs.  Here is le code:

[code]
<p> </p><form name="displayrecord" method="post"
action="updaterecord.php">
  <table width="250" border="1" align="center" cellpadding="3">
    <tr>
      <td colspan="2">
        <div align="center"><b>Update Patient Information</b></div>
      </td>
    </tr>

<?php
require_once('odbc.php');

$query="SELECT * from tblPatient WHERE PatientID='" .$PatientID ."'";
$varquery=odbc_exec($odbc, $query) or die (odbc_errormsg());
if($record=odbc_fetch_array($varquery))
{
    echo "<tr> ";
    echo " <td width=\"100\"> ";
    echo " <div align=\"right\">Patient ID </div>";
    echo " </td>";
    echo " <td width=\"150\"> ";
    echo " <input type=\"text\" name=\"PatientID\" value=\"".$record["PatientID"]."\">";
    echo " </td>";
    echo " </tr>";
    echo "<tr> ";
    echo " <td width=\"100\"> ";
    echo " <div align=\"right\">LName </div>";
    echo " </td>";
    echo " <td width=\"150\"> ";
    echo " <input type=\"text\" name=\"LastName\" value=\"".$record["LastName"]."\">";
    echo " </td>";
    echo " </tr>";
    echo " <tr> ";
    echo " <td width=\"100\"> ";
    echo " <div align=\"right\">FName</div>";
    echo " </td>";
    echo " <td width=\"150\"> ";
    echo " <input type=\"text\" name=\"FirstName\" value=\"".$record["FirstName"]."\">";
    echo " </td>";
    echo " </tr>";
    echo " <tr> ";
    echo " <td width=\"100\"> ";
    echo " <div align=\"right\">Address </div>";
    echo " </td>";
    echo " <td width=\"150\"> ";
    echo " <input type=\"text\" name=\"ADDRESS1\" value=\"".$record["ADDRESS1"]."\">";
    echo " </td>";
    echo " </tr>";
    echo "<tr> ";
    echo " <td width=\"100\"> ";
    echo " <div align=\"right\">Phone </div>";
    echo " </td>";
    echo " <td width=\"150\"> ";
    echo " <input type=\"text\" name=\"HM\" value=\"".$record["HM"]."\">";
    echo " </td>";
    echo " </tr>";
    echo " <tr> ";
    echo " <td colspan=\"2\"> ";
    echo " <div align=\"center\"> ";
    echo " <input type=\"submit\" name=\"Submit\" value=\"Submit\">";
    echo " </div>";
    echo " </td>";
    echo "</tr>";
}
?>  [/code]

This last script accepts the record entered by the end user and updates the record in the MySQL table. 

[code]
<?php
require_once('odbc.php');

$query="UPDATE tblPatient SET ADDRESS1=\"". $ADDRESS1 .
"\" , HM=\"".$HM."\" WHERE PatientID=\"".$PatientID."\"";
$varquery=odbc_exec($odbc, $query);
if (!$varquery)
{
    die(" Query execution failed!!!<br>");
}
else
{
    echo "<table border=\"0\" align=\"center\" cellspacing=\"1\"
    cellpadding=\"5\" width=\"300\">";
    echo " <tr> ";
    echo " <td colspan=\"2\"> ";
    echo " <center><b>".odbc_affected_rows()."record is updated successfully</b></center>";
    echo " </td>";
    echo " </tr>";
    echo " <tr> ";
    echo " <td width=\"100\"> ";
    echo " <div align=\"right\">Patient ID</div>";
    echo " </td>";
    echo " <td width=\"200\">".$PatientID. "</td>";
    echo " </tr>";
    echo " <tr> ";
    echo " <td width=\"100\"> ";
    echo " <div align=\"right\">Last Name</div>";
    echo " </td>";
    echo " <td width=\"200\">".$LastName. "</td>";
    echo " </tr>";
    echo " <tr> ";
    echo " <td width=\"100\"> ";
    echo " <div align=\"right\">First Name</div>";
    echo " </td>";
    echo " <td width=\"200\">".$FirstName. "</td>";
    echo " </tr>";
    echo " <tr> ";
    echo " <td width=\"100\"> ";
    echo " <div align=\"right\">Address</div>";
    echo " </td>";
    echo " <td width=\"200\">".$ADDRESS1. "</td>";
    echo " </tr>";
    echo " <tr> ";
    echo " <td width=\"100\"> ";
    echo " <div align=\"right\">Phone</div>";
    echo " </td>";
    echo " <td width=\"200\">".$HM. "</td>";
    echo " </tr>";
    echo " <tr> ";
    echo " <td colspan=\"2\"> </td>";
    echo " </tr>";
    echo "</table>";
}
?> [/code]

Any and all input is greatly appreciated.  If you feel I am doing something a really stupid way, please let me know.

Adam

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.