Jump to content

Recommended Posts

These pages used to work correctly but now they don't and I just need guidance on where to look to find the problem.

 

I have a page that gets all information from a directory table according to last names. This page works fine. All records fetched have a link to Edit or Delete. When clicking on Edit, the information for the record is passed to another form with all the fields filled in. This works fine too. The problem is that when I edit a piece of information and submit, the form ADDS the corrected record rather than updating the information so I get a whole new record - which is wrong.

 

What do I check to find out why the form is adding a new record rather than updating the current one?

 

Here is the code for my edit record set on the problem page:

 

<?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"] == "form1")) {
 $updateSQL = sprintf("UPDATE Directory SET last_name=%s, first_name=%s, title=%s, rank=%s, job_title1=%s, job_title2=%s, dept_num=%s, location=%s, room=%s, phone=%s, fax=%s, email=%s, doctor=%s, master=%s, bachelor=%s, associate=%s, tier=%s WHERE id=%s",
                      GetSQLValueString($_POST['last_name'], "text"),
                      GetSQLValueString($_POST['first_name'], "text"),
                      GetSQLValueString($_POST['title'], "text"),
                      GetSQLValueString($_POST['rank'], "text"),
                      GetSQLValueString($_POST['job_title1'], "text"),
                      GetSQLValueString($_POST['job_title2'], "text"),
                      GetSQLValueString($_POST['dept_num'], "int"),
                      GetSQLValueString($_POST['location'], "text"),
                      GetSQLValueString($_POST['room'], "text"),
                      GetSQLValueString($_POST['phone'], "text"),
                      GetSQLValueString($_POST['fax'], "text"),
                      GetSQLValueString($_POST['email'], "text"),
                      GetSQLValueString($_POST['doctor'], "text"),
                      GetSQLValueString($_POST['master'], "text"),
                      GetSQLValueString($_POST['bachelor'], "text"),
                      GetSQLValueString($_POST['associate'], "text"),
                      GetSQLValueString($_POST['tier'], "int"),
                      GetSQLValueString($_POST['tier'], "int"));

 mysql_select_db($database_connDESU, $connDESU);
 $Result1 = mysql_query($updateSQL, $connDESU) or die(mysql_error());

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

$colname_rsDirectoryEdit = "1";
if (isset($_GET['id'])) {
 $colname_rsDirectoryEdit = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_connDESU, $connDESU);
$query_rsDirectoryEdit = sprintf("SELECT * FROM Directory WHERE id = %s", $colname_rsDirectoryEdit);
$rsDirectoryEdit = mysql_query($query_rsDirectoryEdit, $connDESU) or die(mysql_error());
$row_rsDirectoryEdit = mysql_fetch_assoc($rsDirectoryEdit);
$totalRows_rsDirectoryEdit = mysql_num_rows($rsDirectoryEdit);
?>

Link to comment
https://forums.phpfreaks.com/topic/1816-edit-record-inserts-instead/
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.