Jump to content


Photo

Trouble with ODBC Edit/Update records form


  • Please log in to reply
4 replies to this topic

#1 Arl8

Arl8
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 21 August 2006 - 07:38 PM

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 http://www.phpfreaks...orials/61/2.php , 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

<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); ?>

**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:

<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>"; 
} 
?> 

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

<?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>"; 
} 
?>

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

Adam

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 21 August 2006 - 07:46 PM

Do you absolutely have to run it on Windows? :-P
PHP Ninja

#3 Arl8

Arl8
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 21 August 2006 - 08:39 PM

Sadly yes.  Keeping this topic fresh.



#4 Arl8

Arl8
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 22 August 2006 - 03:39 PM

Bump.

#5 Arl8

Arl8
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 22 August 2006 - 05:06 PM

Anyone please help? 




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users