473,657 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why does this not update record anyone?

Hello,

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,

rg.

<?
session_start() ;
require_once('C onnections/ppchcust.php');
//go and get the pre update values for the form
$colname_rsedit profile = "1";
if (isset($_SESSIO N['MM_Username'])) {
$colname_rsedit profile = (get_magic_quot es_gpc()) ?
$_SESSION['MM_Username'] : addslashes($_SE SSION['MM_Username']);
}
mysql_select_db ($database_loca l, $local);
$query_rseditpr ofile = sprintf("SELECT custid, password, title,
firstname, surname, company, displayname, `position`, address1,
address2, city, country, postcode, telephone, fax, emailaddress FROM
customers WHERE userid = '%s'", $colname_rsedit profile);
$rseditprofile = mysql_query($qu ery_rseditprofi le, $local) or
die(mysql_error ());
$row_rseditprof ile = mysql_fetch_ass oc($rseditprofi le);
$totalRows_rsed itprofile = mysql_num_rows( $rseditprofile) ;

//this is the update part
function GetSQLValueStri ng($theValue, $theType, $theDefinedValu e = "",
$theNotDefinedV alue = "")
{
$theValue = (!get_magic_quo tes_gpc()) ? addslashes($the Value) :
$theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValu e) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theV alue) . "'"
: "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValu e :
$theNotDefinedV alue;
break;
}
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"] ==
"custregisterfo rm")) {
$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",
GetSQLValueStri ng($_POST['password'], "text"),
GetSQLValueStri ng($_POST['title'], "text"),
GetSQLValueStri ng($_POST['firstname'], "text"),
GetSQLValueStri ng($_POST['surname'], "text"),
GetSQLValueStri ng($_POST['company'], "text"),
GetSQLValueStri ng($_POST['displayname'], "text"),
GetSQLValueStri ng($_POST['position'], "text"),
GetSQLValueStri ng($_POST['address1'], "text"),
GetSQLValueStri ng($_POST['address2'], "text"),
GetSQLValueStri ng($_POST['city'], "text"),
GetSQLValueStri ng($_POST['country'], "text"),
GetSQLValueStri ng($_POST['postcode'], "text"),
GetSQLValueStri ng($_POST['telephone'], "text"),
GetSQLValueStri ng($_POST['fax'], "text"),
GetSQLValueStri ng($_POST['emailaddress'],"text"),
GetSQLValueStri ng($_POST['custid'], "int"));

mysql_select_db ($database_loca l, $local);
$Result1 = mysql_query($up dateSQL, $local) or die(mysql_error ());

// if update ok then redir to somewhere else THIS WORKS....
$updateGoTo = "regeditprofile ok.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($update GoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf( "Location: %s", $updateGoTo));
}
?>
Sep 5 '05 #1
1 1817
toedipper said the following on 06/09/2005 00:06:
Hello,

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,

rg.

<?
session_start() ;
require_once('C onnections/ppchcust.php');


*************** *************** *************** **** //go and get the pre update values for the form
$colname_rsedit profile = "1";
if (isset($_SESSIO N['MM_Username'])) {
$colname_rsedit profile = (get_magic_quot es_gpc()) ?
$_SESSION['MM_Username'] : addslashes($_SE SSION['MM_Username']);
}
mysql_select_db ($database_loca l, $local);
$query_rseditpr ofile = sprintf("SELECT custid, password, title,
firstname, surname, company, displayname, `position`, address1,
address2, city, country, postcode, telephone, fax, emailaddress FROM
customers WHERE userid = '%s'", $colname_rsedit profile);
$rseditprofile = mysql_query($qu ery_rseditprofi le, $local) or
die(mysql_error ());
$row_rseditprof ile = mysql_fetch_ass oc($rseditprofi le);
$totalRows_rsed itprofile = mysql_num_rows( $rseditprofile) ;
*************** *************** *************** *****
^^^^
What is the point of this bit??

//this is the update part
function GetSQLValueStri ng($theValue, $theType, $theDefinedValu e = "",
$theNotDefinedV alue = "")
{
$theValue = (!get_magic_quo tes_gpc()) ? addslashes($the Value) :
$theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValu e) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theV alue) . "'" :
"NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValu e :
$theNotDefinedV alue;
break;
}
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"] ==
"custregisterfo rm")) {
$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",
GetSQLValueStri ng($_POST['password'], "text"),
GetSQLValueStri ng($_POST['title'], "text"),
GetSQLValueStri ng($_POST['firstname'], "text"),
GetSQLValueStri ng($_POST['surname'], "text"),
GetSQLValueStri ng($_POST['company'], "text"),
GetSQLValueStri ng($_POST['displayname'], "text"),
GetSQLValueStri ng($_POST['position'], "text"),
GetSQLValueStri ng($_POST['address1'], "text"),
GetSQLValueStri ng($_POST['address2'], "text"),
GetSQLValueStri ng($_POST['city'], "text"),
GetSQLValueStri ng($_POST['country'], "text"),
GetSQLValueStri ng($_POST['postcode'], "text"),
GetSQLValueStri ng($_POST['telephone'], "text"),
GetSQLValueStri ng($_POST['fax'], "text"),
GetSQLValueStri ng($_POST['emailaddress'],"text"),
GetSQLValueStri ng($_POST['custid'], "int"));

*******

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....

*******
mysql_select_db ($database_loca l, $local);
$Result1 = mysql_query($up dateSQL, $local) or die(mysql_error ());

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

--
Oli
Sep 5 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2773
by: Sue Adams | last post by:
I actually have two issues/questions: I have an autonumber field in an access db table that I grab and later use to update a record in another table withing the same db. The code I use to get it from the db table is: ''Retrieve the Registration Identification Number strRegisterID = Rs("Register_ID") Prior to testing my code and actually updating the db, I''m trying to write it to the page to make sure their isn''t a loop or massive...
3
12961
by: BlackFireNova | last post by:
This concerns an Access 2002 (XP) database. There are two fields, "Notes" (Memo Field) and "Notes Update" on a form (among others) which I am concerned with here. Problem: I need to be able to tell when people have added notes to a record. (this database contains 6000+ records) I want to set it up so that "Notes Update" is updated to the current date whenever someone actually enters data into, or modifies data in, the "Notes"...
1
3670
by: Grant McLean | last post by:
Hi First a simple question ... I have a table "access_log" that has foreign keys "app_id" and "app_user_id" that reference the "application_type" and "app_user" tables. When I insert into "access_log", the referential integrity triggers generate these queries: SELECT 1 FROM ONLY "public"."application_type" x
6
8530
by: Henry Stockbridge | last post by:
Hi, I have a popup that is used to update the records on an open form. I cannot get form to refresh with the new values. Any help you can lend would be appreciated. Here is the code for the popup form: '----------------------------------------------- Sub AddRep_Click() Dim db As Database
2
2329
by: bbasberg | last post by:
I have been working hard to clean up my code but I am still wondering why all incoming records go to the "AddNew" part of the IF statement and never to the Edit alternative. I believe that it must be because my rs.index never really receives the value from the cell in the spreadsheet that it should use to compare to the corresponding field in the Access DB. I have named the field "rtitle" in Access and made it an index called riskIndex. I am an...
3
1674
by: bluefox15 | last post by:
This is my first time posting in a forum for Access, but I've seen a lot of great answers on this site so I'm hoping I can get one for this question. I have an Access database that allows users to store notes. Every time a new note is added, Access stores the userID of the user who created the note in a table, tblNotes, in the column, NoteCreator. I do this with the CurrentUser function in the BeforeUpdate event procedure. I want to...
11
4275
by: stantron | last post by:
Setup: I only have one database with one table in it. The first page has a form that adds a record (w/ 6 fields in it) to the mySQL database's lone table via PHP. This works fine. I also have a PHP table that displays all records in my database on this same page. This too works fine. I have my table set up so that there is a 7th field, called "rid" to act as a "record id" or unique identifying field. This is primary and auto-incremented. There...
13
4165
by: Neil | last post by:
I'm running an update query in SQL 7 from QA, and it runs forever. Has been running for 20 minutes so far! The query is quite simple: update a single field in a table, based on a join with another table. There are a total of 1200 rows that are affected (out of a total of 60,000 in the table). Should not take 20 minutes! Also, retrieving the 1200 rows using the same criteria is instantaneous. Anyone have any idea what's going on? Here's...
2
2629
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to update the information which is stored in a SQL database. In testing we noticed that the form was updating correctly but the update mechanism was also updating the first record of the table in the sql database every time. No error messages are on...
0
8316
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8833
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8610
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6174
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5636
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2735
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1730
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.