Why does this not update record anyone?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

PHP4 and MySql

I have the code below, a mixture of handcoded and Dreamweaver genaratd  
php code.  Basically it's an update record form - I load the values from  
a db and bind text boxes etc.  This works ok.  But I also have an update  
action - if a user changes any of the text box values then he can click  
update and the code should write the new values to the db.  Should, but  
it does'nt!  When I go and look in the db I can see that the values are  
still the old ones.  But it does not trip up either and I have a 'on  
update success' action that redirects to a congrats page and this DOES work.

thanks in advance,



//go and get the pre update values for the form
$colname_rseditprofile = "1";
if (isset($_SESSION['MM_Username'])) {
   $colname_rseditprofile = (get_magic_quotes_gpc()) ?  
$_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
mysql_select_db($database_local, $local);
$query_rseditprofile = sprintf("SELECT custid, password, title,  
firstname, surname, company, displayname, `position`, address1,  
address2, city, country, postcode, telephone, fax, emailaddress FROM  
customers WHERE userid = '%s'", $colname_rseditprofile);
$rseditprofile = mysql_query($query_rseditprofile, $local) or  
$row_rseditprofile = mysql_fetch_assoc($rseditprofile);
$totalRows_rseditprofile = mysql_num_rows($rseditprofile);

//this is the update part
function GetSQLValueString($theValue, $theType, $theDefinedValue = "",  
$theNotDefinedValue = "")
   $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) :  

   switch ($theType) {
     case "text":
       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
     case "long":
     case "int":
       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
     case "double":
       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'"  
: "NULL";
     case "date":
       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
     case "defined":
       $theValue = ($theValue != "") ? $theDefinedValue :  
   return $theValue;

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

//this the actual update code and sql
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] ==  
"custregisterform")) {
   $updateSQL = sprintf("UPDATE customers SET password=%s, title=%s,  
firstname=%s, surname=%s, company=%s, displayname=%s, `position`=%s,  
address1=%s, address2=%s, city=%s, country=%s, postcode=%s,  
telephone=%s, fax=%s, emailaddress=%s WHERE custid=%s",
                        GetSQLValueString($_POST['password'], "text"),
                        GetSQLValueString($_POST['title'], "text"),
                        GetSQLValueString($_POST['firstname'], "text"),
                        GetSQLValueString($_POST['surname'], "text"),
                        GetSQLValueString($_POST['company'], "text"),
                        GetSQLValueString($_POST['displayname'], "text"),
                        GetSQLValueString($_POST['position'], "text"),
                        GetSQLValueString($_POST['address1'], "text"),
                        GetSQLValueString($_POST['address2'], "text"),
                        GetSQLValueString($_POST['city'], "text"),
                        GetSQLValueString($_POST['country'], "text"),
                        GetSQLValueString($_POST['postcode'], "text"),
                        GetSQLValueString($_POST['telephone'], "text"),
                        GetSQLValueString($_POST['fax'], "text"),
                        GetSQLValueString($_POST['custid'], "int"));

   mysql_select_db($database_local, $local);
   $Result1 = mysql_query($updateSQL, $local) or die(mysql_error());

// if update ok then redir to somewhere else  THIS WORKS....
   $updateGoTo = "regeditprofileok.php";
   if (isset($_SERVER['QUERY_STRING'])) {
     $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
     $updateGoTo .= $_SERVER['QUERY_STRING'];
   header(sprintf("Location: %s", $updateGoTo));

Re: Why does this not update record anyone?

toedipper said the following on 06/09/2005 00:06:
Quoted text here. Click to load it

Quoted text here. Click to load it
What is the point of this bit??

Quoted text here. Click to load it


I would highly recommend doing an echo of $updateSQL at this point, to  
ensure that the query syntax and POST values are as expected.

Of course, you will need to disable the redirect below....


Quoted text here. Click to load it


Site Timeline