473,728 Members | 1,712 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 1820
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
2779
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
12969
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
3687
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
8532
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
2333
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
1678
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
4281
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
4172
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
2635
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
8753
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
9265
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9188
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9122
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...
0
8113
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6704
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
4522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4787
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.