Link to home
Start Free TrialLog in
Avatar of kenuk110
kenuk110

asked on

Update form in Dreamweaver CS4 not updating records.

Hi,

I have created an update for using the built in Record Update Wizard in Dreamweaver but it will not update a record.

I tried installing WebAssist Data Assist and went through the wizard in that to do the same thing but still it doesn't work. I then created an Insert screen, this, works fine and inserts records.

I have attached the code for the Dreamweaver created page....any ideas? If providing anything else would help, please don't hesitate to ask

Best Regards

Ken
<?php require_once('../../Connections/t1.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
 
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE BTW SET AssociateID=%s, BTWDate=%s, DocsConfirmed=%s, DocsReviewDate=%s, DocsScanned=%s, WarningLetterIssued=%s, WarningLetterDate=%s, AssociateName=%s, DocsReceived=%s WHERE pk=%s",
                       GetSQLValueString($_POST['AssociateID'], "text"),
                       GetSQLValueString($_POST['BTWDate'], "date"),
                       GetSQLValueString(isset($_POST['DocsConfirmed']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['DocsReviewDate'], "date"),
                       GetSQLValueString(isset($_POST['DocsScanned']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString(isset($_POST['WarningLetterIssued']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['WarningLetterDate'], "date"),
                       GetSQLValueString($_POST['AssociateName'], "text"),
                       GetSQLValueString(isset($_POST['DocsReceived']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['pk'], "int"));
 
  mysql_select_db($database_t1, $t1);
  $Result1 = mysql_query($updateSQL, $t1) or die(mysql_error());
}
 
mysql_select_db($database_t1, $t1);
$query_Recordset1 = "SELECT * FROM BTW";
$Recordset1 = mysql_query($query_Recordset1, $t1) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
 
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Pk:</td>
      <td><?php echo $row_Recordset1['pk']; ?></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">AssociateID:</td>
      <td><input type="text" name="AssociateID" value="<?php echo htmlentities($row_Recordset1['AssociateID'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">BTWDate:</td>
      <td><input type="text" name="BTWDate" value="<?php echo htmlentities($row_Recordset1['BTWDate'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">DocsConfirmed:</td>
      <td><input type="checkbox" name="DocsConfirmed" value=""  <?php if (!(strcmp($row_Recordset1['DocsConfirmed'],""))) {echo "checked=\"checked\"";} ?> /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">DocsReviewDate:</td>
      <td><input type="text" name="DocsReviewDate" value="<?php echo htmlentities($row_Recordset1['DocsReviewDate'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">DocsScanned:</td>
      <td><input type="checkbox" name="DocsScanned" value=""  <?php if (!(strcmp($row_Recordset1['DocsScanned'],""))) {echo "checked=\"checked\"";} ?> /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">WarningLetterIssued:</td>
      <td><input type="checkbox" name="WarningLetterIssued" value=""  <?php if (!(strcmp($row_Recordset1['WarningLetterIssued'],""))) {echo "checked=\"checked\"";} ?> /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">WarningLetterDate:</td>
      <td><input type="text" name="WarningLetterDate" value="<?php echo htmlentities($row_Recordset1['WarningLetterDate'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">AssociateName:</td>
      <td><input type="text" name="AssociateName" value="<?php echo htmlentities($row_Recordset1['AssociateName'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">DocsReceived:</td>
      <td><input type="checkbox" name="DocsReceived" value=""  <?php if (!(strcmp($row_Recordset1['DocsReceived'],""))) {echo "checked=\"checked\"";} ?> /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Update record" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1" />
  <input type="hidden" name="pk" value="<?php echo $row_Recordset1['pk']; ?>" />
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Open in new window

Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

It looks you've built the Update Behavior incorrectly.

Update Behaviors require that you pass the primary key of the row being updated back through the form to the server.  So you have the PK defined correctly here:

<input type="hidden" name="pk" value="<?php echo $row_Recordset1['pk']; ?>" />

But this section of the PHP is missing a step:

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
 
(there should be some additional PHP code here)

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {

What I THINK you have done is create the update behavior but did not associate the Primary Key field in the table with the hidden field in the form.  See the attached screenshot.

You need to set the indicated areas correctly and the update behavior will work.
ASKER CERTIFIED SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kenuk110
kenuk110

ASKER

Thanks for the update Jason.

I tried what you suggested but it still didn't allow the update. What I did do though was a search on field types able to accept update - random google search - and someone had issues with updating a field in a database set to BIT. I tested updating the name of the person on the form and the update was fine, I changed the name from Tom to TomUpdate and it kept the update. I then went and changed all the other fields to CHAR and the updates work fine.

I'm still not sure though if a form should be able to update a BIT field or not but the way round was to change it to CHAR. Does this make sense to you?

Regards

Ken
I've never used a bit column so I've never run into that issue.