Jump to content


Photo

Updating via submit button reloads current page with old information


  • Please log in to reply
2 replies to this topic

#1 Theora

Theora
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 18 August 2006 - 03:16 PM

I'm trying to allow someone to update a record (using the Update Record server behavior in Dreamweaver 8 ) and upon completion redirect to the page "admin.php". For some reason when the submit button is pressed the page simply reloads and the fields contain the original information with all changes lost. Any idea what's going wrong? Thanks... following is the code.

<?php require_once('Connections/content.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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"] == "updating")) {
  $updateSQL = sprintf("UPDATE content SET primary_con=%s, pagecontent_con=%s, updated_con=%s WHERE pagename_con=%s",
                       GetSQLValueString($_POST['key'], "int"),
                       GetSQLValueString($_POST['textarea'], "text"),
                       GetSQLValueString($_POST['updated'], "date"),
                       GetSQLValueString($_POST['pagename'], "text"));

  mysql_select_db($database_content, $content);
  $Result1 = mysql_query($updateSQL, $content) or die(mysql_error());

  $updateGoTo = "admin.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_rsEdit = "-1";
if (isset($_GET['recordID'])) {
  $colname_rsEdit = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
}
mysql_select_db($database_content, $content);
$query_rsEdit = sprintf("SELECT * FROM content WHERE pagename_con = '%s'", $colname_rsEdit);
$rsEdit = mysql_query($query_rsEdit, $content) or die(mysql_error());
$row_rsEdit = mysql_fetch_assoc($rsEdit);
$totalRows_rsEdit = mysql_num_rows($rsEdit);
?>
<!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=ISO-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form id="updating" name="updating" method="POST" action="<?php echo $editFormAction; ?>">
  <table width="500" border="0" align="center" cellpadding="15" cellspacing="0">
    <tr>
      <td><input name="key" type="hidden" id="key" value="<?php echo $row_rsEdit['primary_con']; ?>" />
        <input name="pagename" type="hidden" id="pagename" value="<?php echo $row_rsEdit['pagename_con']; ?>" />
        Updating <?php echo ucfirst($row_rsEdit['pagename_con']); ?></td>
    </tr>
    <tr>
      <td><textarea name="textarea" cols="55" rows="20"><?php echo $row_rsEdit['pagecontent_con']; ?></textarea></td>
    </tr>
    <tr>
      <td><input name="updated" type="hidden" id="updated" value="<?php echo $row_rsEdit['updated_con']; ?>" />
      <input name="Update" type="submit" id="Update" value="Submit" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="updating">
</form>
</body>
</html>
<?php
mysql_free_result($rsEdit);
?>


#2 Carter7

Carter7
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • LocationUK

Posted 26 August 2006 - 12:04 AM

I had the same problem with a script i wrote myself, i do not quite know how i over come it, though it still updates it in the database it just does not show the updated information, this could be because of where you update process is.

#3 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 26 August 2006 - 01:06 AM

if (isset($_GET['recordID'])) {

I don't see anywhere in your code where recordID is passed.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users