Skip to main content
Inspiring
September 9, 2011
Question

Form Update refuses to work!

  • September 9, 2011
  • 1 reply
  • 736 views

Can anyone see what I am doing wrong in this update form?

I have redone it over and over but it still refuses to keep the changes that have been made. Any ideas please!!!

<?php require_once('Connections/LeHerissonConnection.php'); ?>

<?php $urlmsg = (isset($_GET["msg"])) ? $_GET["msg"] : ""; ?>

<?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"] == "EditMember")) {

  $updateSQL = sprintf("UPDATE members SET Firstname=%s, Surname=%s, `Section`=%s, Login=%s, Password=%s, DefaultPassword=%s, Email=%s WHERE id=%s",

                       GetSQLValueString($_POST['Firstname'], "text"),

                       GetSQLValueString($_POST['Surname'], "text"),

                       GetSQLValueString($_POST['Section'], "text"),

                       GetSQLValueString($_POST['Login'], "text"),

                       GetSQLValueString($_POST['Password'], "text"),

                       GetSQLValueString($_POST['DefaultPassword'], "text"),

                       GetSQLValueString($_POST['Email'], "text"),

                       GetSQLValueString($_POST['id'], "int"));

  mysql_select_db($database_LeHerissonConnection, $LeHerissonConnection);

  $Result1 = mysql_query($updateSQL, $LeHerissonConnection) or die(mysql_error());

}

$colname_MembersFromURL = "-1";

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

  $colname_MembersFromURL = $_GET['id'];

}

mysql_select_db($database_LeHerissonConnection, $LeHerissonConnection);

$query_MembersFromURL = sprintf("SELECT * FROM members WHERE id = %s", GetSQLValueString($colname_MembersFromURL, "int"));

$MembersFromURL = mysql_query($query_MembersFromURL, $LeHerissonConnection) or die(mysql_error());

$row_MembersFromURL = mysql_fetch_assoc($MembersFromURL);

$totalRows_MembersFromURL = mysql_num_rows($MembersFromURL);

?>

<style type="text/css">

th { font-weight: bold; text-transform: uppercase; color: #00F; text-align: left; border-bottom: 1px solid #000; padding: 2px 0 3px 0; }

td { border-bottom: 1px solid #000; padding: 2px 0 3px 0; }

</style>

<table width="600" border="0" cellspacing="0" cellpadding="0">

<form action="<?php echo $editFormAction; ?>" name="EditMember" method="POST" id="EditMember">

  <tr>

    <th>ID</th>

    <td><input name="id" type="text" disabled id="id" value="<?php echo $row_MembersFromURL['id']; ?>" size="5"></td>

  </tr>

  <tr>

    <th>First Name</th>

    <td><input name="Firstname" type="text" id="Firstname" value="<?php echo $row_MembersFromURL['Firstname']; ?>"></td>

  </tr>

  <tr>

    <th>Surname</th>

    <td><input name="Surname" type="text" id="Surname" value="<?php echo $row_MembersFromURL['Surname']; ?>"></td>

  </tr>

  <tr>

    <th>Section</th>

    <td><input name="Section" type="text" id="Section" value="<?php echo $row_MembersFromURL['Section']; ?>"></td>

  </tr>

  <tr>

    <th>Login</th>

    <td><input name="Login" type="text" id="Login" value="<?php echo $row_MembersFromURL['Login']; ?>"></td>

  </tr>

  <tr>

    <th>Password</th>

    <td><input name="Password" type="text" id="Password" value="<?php echo $row_MembersFromURL['Password']; ?>"></td>

  </tr>

  <tr>

    <th>Default Password</th>

    <td><input name="DefaultPassword" type="text" id="DefaultPassword" value="<?php echo $row_MembersFromURL['DefaultPassword']; ?>"></td>

  </tr>

  <tr>

    <th>Email</th>

    <td><input name="Email" type="text" id="Email" value="<?php echo $row_MembersFromURL['Email']; ?>"></td>

  </tr>

  <tr>

    <th><input type="hidden" name="MM_update" value="EditMember"></th>

    <td><input type="submit" name="Update" id="Update" value="Submit"></td>

  </tr>

  </form>

</table>

<?php

mysql_free_result($MembersFromURL);

?>

This topic has been closed for replies.

1 reply

Lon_Winters
Inspiring
September 9, 2011

Are you using the standard update record server behavior and does it redirect successfully?

Inspiring
September 9, 2011

Sorry - I have no idea. I have only done what Dreamweaver came up with, so I guess it is standard.

Then clicking on update it just clears whatever changes I made before and shows the same page again.

Lon_Winters
Inspiring
September 9, 2011

If you are using the update server behavior, you would have added it through the server behaviors panel - update record. This requires a recordset on the page first. Typical set up is create the recordset, bind the recordset fields to the form fields so the current data displays in the form fields. Apply the update behavior, making sure to identify the recordset and unique ID key column and specify the redirect page.

This is the only process I'm aware of of what DW will tell you what to do with the exception of 3rd party extensions that do similar things. Also, make sure that the firm action does nit contain a link to another page. If this is not the process you are using, then we'll need to step back and see what's going on.