473,382 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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('Connections/ppchcust.php');
//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
die(mysql_error());
$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) :
$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']);
}

//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['emailaddress'],"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));
}
?>
Sep 5 '05 #1
1 1804
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('Connections/ppchcust.php');


************************************************* //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
die(mysql_error());
$row_rseditprofile = mysql_fetch_assoc($rseditprofile);
$totalRows_rseditprofile = mysql_num_rows($rseditprofile);
**************************************************
^^^^
What is the point of this bit??

//this is the update part
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']);
}

//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['emailaddress'],"text"),
GetSQLValueString($_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_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));
}
?>

--
Oli
Sep 5 '05 #2

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

Similar topics

0
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...
3
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...
1
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...
6
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...
2
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...
3
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...
11
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...
13
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.