Jump to content

Recommended Posts

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)

Link to comment
https://forums.phpfreaks.com/topic/94704-cant-update-the-table/
Share on other sites

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.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/94704-cant-update-the-table/#findComment-484879
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/94704-cant-update-the-table/#findComment-484906
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/94704-cant-update-the-table/#findComment-484929
Share on other sites

Where is id_incr getting set from and how?

 

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/94704-cant-update-the-table/#findComment-484954
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/94704-cant-update-the-table/#findComment-485137
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • 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.