Jump to content
Xisto Corporation
Sign in to follow this  

Odbc Form Problems

Recommended Posts

Hy everyone!

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

Basic information about my system:

MySQL 4.1
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://forums.xisto.com/no_longer_exists/ , 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=\"".$row["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=\"".$row["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=mysql_query($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\">".$phone. "</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.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.