Jump to content

jeff5656

Members
  • Posts

    744
  • Joined

  • Last visited

Everything posted by jeff5656

  1. I added this to the form but still no dice: <td><input type="hidden" name ="id_incr" value="<?php echo $id_incr; ?>"/></td>
  2. I'm bumping because posting rules said I could do it if no answer after a few hours. I can't get beyond this point. I cannot update the table because the id_incr field of the record is 1, instead of the actual value (i.e. 46), so the commit.php script does not successfully update the table. Also, the signoff_status value gets lost by the time it arrives in the commit.php script.
  3. First, the following table is displayed. <?php require('secure.php'); include "dateheader.php"; include "connectdb.php"; $query = "SELECT id_incr, patient_name, mrn, location, fellow, rcf_date, admission, consult_reason, impression, recs, comments ". "FROM active_consults WHERE signoff_status = 'a' ". "ORDER BY patient_name"; $results = mysql_query ($query) or die (mysql_error()); $num_pts = mysql_num_rows ($results); $consultheading =<<<EOD <table width="70%" border = "1" cellpadding = "2" cellspacing = "2" align = "center"> <th> Name </th> <th> MRN </th> <th> Loc </th> <th> Fellow </th> <th> Date of Consult</th> <th> Reason for Admssion </th> <th> Reason for Consult </th> <th> Impression </th> <th> Recs </th> <th> Comments </th> </tr> EOD; echo $consultheading; while ($row = mysql_fetch_assoc ($results)) { ?> <tr> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['patient_name'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['mrn'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['location'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['fellow'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['rcf_date'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['admission'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['consult_reason'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['impression'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['recs'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['comments'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <a href="editpatient.php?action=edit&id=<?php echo $row['id_incr']; ?>">[EDIT]</a> </td> </tr> <?php } ?> <td> Total active patients: <?php echo $num_pts; ?> </td> </tr> </table> <a href="newpatient.php">[ADD PATIENT]</a> If a user clicks the [edit] href, link, the following code is displayed (editpatient.php): <?php require('secure.php'); include "dateheader.php"; include "connectdb.php"; switch ($_GET['action']) { case "edit": $consultsq1 = "SELECT * FROM active_consults WHERE id_incr = '" . $_GET['id'] . "'"; $result = mysql_query ($consultsq1) or die ("Invalid query: " . mysql_error ()); $row = mysql_fetch_array ($result); $patient_name = $row['patient_name']; $mrn = $row['mrn']; $location = $row['location']; $fellow = $row['fellow']; $rcf_date = $row['rcf_date']; $admission = $row['admission']; $consult_reason = $row['consult_reason']; $impression = $row['impression']; $recs = $row['recs']; $comments = $row['comments']; break; default: $patient_name = ""; $mrn = ""; $location = ""; $fellow = ""; $rcf_date = ""; $admission = ""; $consult_reason = ""; $impression = ""; $recs = ""; $comments = ""; break; } ?> <html> <head> <title>Update Patient</title> </head> <body> <form action="commit.php"?action=<?php echo $_GET['action']; ?>&type=active_consults&id=<?php echo $_GET['id']; ?>" method="post"> <table width="200" border="0"> <tr> <th scope="col">Patient Name</th> <th scope="col">MRN</th> <th scope="col">Loc</th> <th scope="col">Fellow</th> </tr> <tr> <td><input name="patient_name" type="text" size="20" value="<? echo $patient_name; ?>" /></td> <td><input type="text" name="mrn" size="10" value="<? echo $mrn; ?>"/></td> <td><label> <input name="location" type="text" id="location" size="6" value="<? echo $loc; ?>"/> </label></td> <td><label> <input type="text" name="fellow" id="fellow" value="<? echo $fellow; ?>" /> </label></td> </tr> </table> <p> </p> <table width="391" border="0"> <tr> <th scope="col"><div align="left">Date of consult: </div></th> <th scope="col"><div align="left"> <input type="text" value="<? echo $rcf_date; ?>" name="rcf_date" /> </div></th> </tr> <tr> <th width="153" scope="col"><div align="left">Reason for admission: </div> <label></label></th> <th width="222" scope="col"><div align="left"> <input type="text" name="admission" id="admission" value="<? echo $admission; ?>"/> </div></th> </tr> <tr> <th><div align="left">Reason for consult: </div> <label></label></th> <td><div align="left"> <input type="text" name="consult_reason" id="consult_reason" value="<? echo $consult_reason; ?>"/> </div></td> </tr> <tr> <th><div align="left">Impression</div></th> <td><input type="text" name="impression" id="impression" value="<? echo $impression; ?>"/></td> </tr> <tr> <th><div align="left">Recs</div></th> <td><input type="text" name="recs" id="recs" value="<? echo $recs; ?>"/></td> </tr> <tr> <th><div align="left">Comments</div></th> <td><label> <textarea name="comments" id="comments" cols="45" rows="3" value="<? echo $comments; ?>"> </textarea> </label></td> <td><select name = "signoff_status" > <option value = "<?php echo $signoff_status; ?>" selected>Active <option value = "s">Sign off </select> </tr> <tr><td><input type="submit" value="Update patient"></form> When a user updates whatever fields they need to in this form, the data is submitted to the following (commit.php): <?php require('secure.php'); include "dateheader.php"; include "connectdb.php"; echo $_POST['patient_name']; echo $_GET['id']; echo "<br/>"; echo "Results: "; echo $_POST['recs']; echo "id_incr: "; echo $_post['id_incr']; $sql = "UPDATE active_consults SET patient_name = '" . $_POST['patient_name'] . "', mrn = '" . $_POST['mrn'] . "', location = '" . $_POST['location'] . "', fellow = '" . $_POST['fellow'] . "', rcf_date = '" . $_POST['rcf_date'] . "', admission = '" . $_POST['admission'] . "', consult_reason = '" . $_POST['consult_reason'] . "', impression = '" . $_POST['impression'] . "', recs = '" . $_POST['recs'] . "', comments = '" . $_POST['comments'] . "', signoff_status = '" . $_POST['signoff_status'] . "' WHERE id_incr = '" . $_GET['id'] . "'"; if (isset($sql) && !empty($sql)) { echo "<!--" . $sql . "-->"; $result = mysql_query($sql) or die ("Invalid query: " . mysql_error()); echo $result; echo "id_incr: "; echo $id_incr; echo "<p>"; echo "sql: "; echo $sql; ?> <p> Done <?php } ?> There are a bunch of echo commands in this when I am trying to debug it.
  4. Here's the echo of $sql again with all fields having a value put in: UPDATE active_consults SET patient_name = 'EWFREWFTERWTFEWR', mrn = '12345', location = 'c-loc', fellow = 'fellow here', rcf_date = 'Mar 5 08', admission = 'also added in phpadm', consult_reason = 'consult reason', impression = 'pneumonia', recs = 'my recs are this', comments = ' my comments', signoff_status = '' WHERE id_incr = '' Looks like signoff_status and id_incr are not getting passed from the form!
  5. When I echo sql I get: UPDATE active_consults SET patient_name = 'jonny come lately', mrn = '44444qwwewe', location = '', fellow = 'stewie', rcf_date = 'Mar 5 08', admission = 'pnba', consult_reason = 'ptx', impression = 'ptx', recs = 'chest tube', comments = ' ', signoff_status = '' WHERE id_incr = ''done
  6. Thank you the syntax error is corrected but the table does not get updated - I do get the sentence "done" that indicates no errors, but when I re-display the table, those fields are not updated or changed. As a test I echoed the $result and get: 1. When I echoed the other fields (like echo $_POST['recs']; I get the updated values. The reason why the table is not getting updated is because it looks like the id_incr field is not correct. Instead, it has a value of 1.
  7. In a previous post I wasn't able to pre-populate a form from a record a user was editing. With help from this forum I have solved that. The new problem is when I try to update the table I get error: [...] syntax to use near '''' WHERE id_incr = ''' at line 12. Ok the first script is the one where the form gets pre-populated successfully. I include it below: <?php require('secure.php'); include "dateheader.php"; include "connectdb.php"; switch ($_GET['action']) { case "edit": $consultsq1 = "SELECT * FROM active_consults WHERE id_incr = '" . $_GET['id'] . "'"; $result = mysql_query ($consultsq1) or die ("Invalid query: " . mysql_error ()); $row = mysql_fetch_array ($result); $patient_name = $row['patient_name']; $mrn = $row['mrn']; $location = $row['location']; $fellow = $row['fellow']; $rcf_date = $row['rcf_date']; $admission = $row['admission']; $consult_reason = $row['consult_reason']; $impression = $row['impression']; $recs = $row['recs']; $comments = $row['comments']; break; default: $patient_name = ""; $mrn = ""; $location = ""; $fellow = ""; $rcf_date = ""; $admission = ""; $consult_reason = ""; $impression = ""; $recs = ""; $comments = ""; break; } ?> <html> <head> <title>Update Patient</title> </head> <body> <form action="commit.php"?action=<?php echo $_GET['action']; ?>&type=active_consults&id=<?php echo $_GET['id']; ?>" method="post"> <table width="200" border="0"> <tr> <th scope="col">Patient Name</th> <th scope="col">MRN</th> <th scope="col">Loc</th> <th scope="col">Fellow</th> </tr> <tr> <td><input name="patient_name" type="text" size="20" value="<? echo $patient_name; ?>" /></td> <td><input type="text" name="mrn" size="10" value="<? echo $mrn; ?>"/></td> <td><label> <input name="location" type="text" id="location" size="6" value="<? echo $loc; ?>"/> </label></td> <td><label> <input type="text" name="fellow" id="fellow" value="<? echo $fellow; ?>" /> </label></td> </tr> </table> <p> </p> <table width="391" border="0"> <tr> <th scope="col"><div align="left">Date of consult: </div></th> <th scope="col"><div align="left"> <input type="text" value="<? echo $rcf_date; ?>" name="rcf_date" /> </div></th> </tr> <tr> <th width="153" scope="col"><div align="left">Reason for admission: </div> <label></label></th> <th width="222" scope="col"><div align="left"> <input type="text" name="admission" id="admission" value="<? echo $admission; ?>"/> </div></th> </tr> <tr> <th><div align="left">Reason for consult: </div> <label></label></th> <td><div align="left"> <input type="text" name="consult_reason" id="consult_reason" value="<? echo $consult_reason; ?>"/> </div></td> </tr> <tr> <th><div align="left">Impression</div></th> <td><input type="text" name="impression" id="impression" value="<? echo $impression; ?>"/></td> </tr> <tr> <th><div align="left">Recs</div></th> <td><input type="text" name="recs" id="recs" value="<? echo $recs; ?>"/></td> </tr> <tr> <th><div align="left">Comments</div></th> <td><label> <textarea name="comments" id="comments" cols="45" rows="3" value="<? echo $comments; ?>"> </textarea> </label></td> <td><select name = "signoff_status" > <option value = "<?php echo $signoff_status; ?>" selected>Active <option value = "s">Sign off </select> </tr> <tr><td><input type="submit" value="Update patient"></form> The commit.php script below, is the one with the error at line 12. <?php require('secure.php'); include "dateheader.php"; include "connectdb.php"; $sql = "UPDATE active_consults SET patient_name = '" . $_POST['patient_name'] . "', mrn = '" . $_POST['mrn'] . "', location = '" . $_POST['location'] . "', fellow = '" . $_POST['fellow'] . "', rcf_date = '" . $_POST['rcf_date'] . "', admission = '" . $_POST['admission'] . "', consult_reason = '" . $_POST['consult_reason'] . "', impression = '" . $_POST['impression'] . "', recs = '" . $_POST['recs'] . "', comments = '" . $_POST['comments'] . "', signoff_status = '" . $_POST['signoff_status'] . "'' WHERE id_incr = '" . $_GET['id'] . "'"; if (isset($sql) && !empty($sql)) { echo "<!--" . $sql . "-->"; $result = mysql_query($sql) or die ("Invalid query: " . mysql_error()); ?> done <?php } ?> I have a feeling I am not doing ther WHERE line correctly. I want to tell the table which record to update and am using the unique identifier called id_incr (which is an auto-incrementer-type field in my table)
  8. BTW, the page preceding the above page is attached below, in case the problem is that this script is sending empty variables (although as I said, the correct id_incr value is displayed in the address bar: <?php require('secure.php'); include "dateheader.php"; include "connectdb.php"; $query = "SELECT id_incr, patient_name, mrn, location, fellow, rcf_date, admission, consult_reason, impression, recs, comments ". "FROM active_consults WHERE signoff_status = 'a' ". "ORDER BY patient_name"; $results = mysql_query ($query) or die (mysql_error()); $num_pts = mysql_num_rows ($results); $consultheading =<<<EOD <table width="70%" border = "1" cellpadding = "2" cellspacing = "2" align = "center"> <th> Name </th> <th> MRN </th> <th> Loc </th> <th> Fellow </th> <th> Date of Consult</th> <th> Reason for Admssion </th> <th> Reason for Consult </th> <th> Impression </th> <th> Recs </th> <th> Comments </th> </tr> EOD; echo $consultheading; while ($row = mysql_fetch_assoc ($results)) { ?> <tr> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['patient_name'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['mrn'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['location'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['fellow'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['rcf_date'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['admission'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['consult_reason'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['impression'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['recs'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <?php echo $row['comments'];?> </td> <td bgcolor="#CCCCCC" width="50%"> <a href="editpatient.php?action=edit&id=<?php echo $row['id_incr']; ?>">[EDIT]</a> </td> </tr> <?php } ?> <td> Total active patients: <?php echo $num_pts; ?> </td> </tr> </table>
  9. Thanks for all the help so far. I managed to get that to be without errors, but now it seems that the variables are empty (but in the address bar I DO see the correct id: http://localhost/consults/editpatient.php?action=edit&id=47) For instance if i try to echo $patient_name nothing is displayed. I added a form to the end (see code below) to try to populate it witht he fields from the record specified in id_incr, but nothing shows up (I got rid of most of the form to make it easier): <?php include 'connectdb.php'; if(isset($_GET['id_incr']) && is_numeric($_GET['id_incr'])) { $patient_name = mysql_real_escape_string($_POST['patient_name']); $mrn = mysql_real_escape_string($_POST['mrn']); $location = mysql_real_escape_string($_POST['location']); $fellow = mysql_real_escape_string($_POST['fellow']); $rcf_date = mysql_real_escape_string($_POST['rcf_date']); $admission = mysql_real_escape_string($_POST['admission']); $consult_reason = mysql_real_escape_string($_POST['consult_reason']); $impression = mysql_real_escape_string($_POST['impression']); $recs = mysql_real_escape_string($_POST['recs']); $admission = mysql_real_escape_string($_POST['admission']); $comments = mysql_real_escape_string($_POST['comments']); $sql = "UPDATE active_consults SET patient_name = '" . $patient_name . "', mrn = '" . $mrn . "', location = '" . $location . "', fellow = '" . $fellow . "', rcf_date = '" . $rcf_date . "', admission = '" . $admission . "', consult_reason = '" . $consult_reason . "', impression = '" . $impression . "', recs = '" . $recs . "', comments = '" . $comments . "' WHERE id_incr = '". $id . "'"; } ?> <h2>Add new patient</h2> <form name="updatepatient" method="post" action="updatepatient.php"> <table width="200" border="0"> <tr> <th scope="col">Patient Name</th> <th scope="col">MRN</th> <th scope="col">Loc</th> <th scope="col">Fellow</th> </tr> <tr> <td><input name="patient_name" type="text" size="20" value="<? echo $patient_name; ?>" /></td> <td><input type="text" name="mrn" size="10"/></td> <td><label> <input name="location" type="text" id="location" size="6" /> </label></td> </tr> </table> <p> </p> <table width="391" border="0"> </table> <label></label> <p> <input type="submit" value="Add patient" /> <input type="reset" value="Clear all fields"/> </p> </form>
  10. I used the code from wildteen 88 and got this: unexpected T_BOOLEAN_AND, expecting ',' or ')' in C:\wamp\www\consults\editpatient.php on line 6
  11. I get the above syntax error with the following code: <?php include connectdb.php $sql = UPDATE active_consults SET patient_name = '" . $_POST['patient_name'] . "', mrn = '" . $_POST['mrn'] . "', location = '" . $_POST['location'] . "', fellow = '" . $_POST['fellow'] . "', rcf_date = '" . $_POST['rcf_date'] . "', admission = '" . $_POST['admission'] . "', consult_reason = '" . $_POST['consult_reason'] . "', impression = '" . $_POST['impression'] . "', recs = '" . $_POST['recs'] . "', comments = '" . $_POST['comments'] . "' where id_incr = '". $_GET['id_incr'] . "'; ?> Thank you!
  12. Thank you that worked! (I was inside html FYI).
  13. I couldnt edit my post I meant this: $current_date = date ("M j y"); <input type="text" name="current_date" value="$current_date" /> but this also does not work: <input type="text" name="current_date" value="current_date" /> (they just dump that specific text into the field).
  14. In a form, I want the current date to be in the date field as a default (but the user can delete that and enter their own if they want). The following was tried but date is not display when I run the script <php $current_date = date (M j y); [.... snip some code here such as creting the form, etc.] <th scope="col"><div align="left">Date of consult: </div></th> <th scope="col"><div align="left"> <input type="text" name="$current_date" /> Now I tried that with and without the $ sign. Thank you. Will display more code if you need it, but the form itself comes aftrer the <html> and <form> but the ?> is at the very end of the whole thing...
  15. Wow people reply quickly on this site! I see how $connect gets executed now, but then why assign it instead of just running mysql_connect( etc...) alone? As for ohdang88, that was just a test database. the usernames and pws will not be like that when I create the real database after I learn how to do all this! But thanks for pointing that out. you said "...But if your query was getting info from a database, then you would need to use $result" Why would you then need to use $result?
  16. I am learning PHP and MYSQL. I have a question which is very likely to be simple for everyone reading this, but i can't get beyond the book until I understand this. In the following code for creating a database: <?php include 'config.php'; include 'opendb.php'; $query = "CREATE DATABASE phpcake"; $result = mysql_query($query); include 'closedb.php'; ?> How is the database phpcake created if the command to create it is assigned to a variable ($query)? Another example in the book: $connect = mysql_connect ("local host", "bp5am", "bpmpass") or die ("can not connect"); But the rest of the example never refers to the variable $connect! So how did it connect? Shouldn't the code have read: mysql_connect ("local host", "bp5am", "bpmpass") or die ("can not connect"); without the variable assignment?
×
×
  • Create New...

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.