I've been using "id" in dozens of databases for more than five years, use it routinely for the unique identifier field, and I've never had the least bit of problem with it. It's in use with about 30 databases in this application right now and is causing no problems. Unless, of course, it is the source of this problem.
I know that two of the fields were altered, and that Nused was blanked. I'm not guessing at that, I'm using phpmyadmin to inspect the actual record and verify that, so I don't really need
mysql_affected_rows() to tell me that one record was altered.
I have structured this SQL statement about two dozen different ways. I have done it with backticks and without backticks. I have done it with spaces before the commas and without spaces before the commas.
This script
Code: Select all
if (isset($_POST['Okay_x'])) // adding or revising: user approved data
{ // ($_POST['id'] will have a value of zero if adding)
$Ver = mysql_real_escape_string($_POST['Verif'],$Link); // $_POST['Okay_x'] just apporves data in the form
$Name = mysql_real_escape_string($_POST['Name'],$Link);
$Inq = mysql_real_escape_string($_POST['Inq'],$Link); // magic quotes is off, so the $_POST is clean
$Nused = mysql_real_escape_string($_POST['Nused'],$Link);
$Comm = mysql_real_escape_string($_POST['Comm'],$Link);
$Cash = 0 + $_POST['Cash'];
$Query = "SELECT Arch FROM Precord WHERE id=". $_POST['id'];
$Result = mysql_query($Query, $Link); // read it whether checkbox set or not
$Row = mysql_fetch_array($Result); // so as to preserve original setting
$A = 0 + $Row['Arch']; // if checkbox is not checked
if (isset($_POST['Arch']))
$A = ($Row['Arch'] > 0) ? 0 : 1; // will move really old ones to current period
$Query = "UPDATE Precord SET Name='$Name',Verif='$Ver',Inq='$Inq',Nused='$Nused',Comment='$Comm',log=$Cash,Arch=$A WHERE id=" . $_POST['id'];
}
produces this SQL statement, which updates the Nused field properly.
Code: Select all
UPDATE Precord SET Name='Shari',Verif='employee list-10/7/08',Inq='holiday savings club',Nused='not requested',Comment='',log=1025,Arch=0 WHERE id=20657
This script
Code: Select all
if (isset($_POST['Type'])) // approved the addition/revision of a staff record
{
$Ptypes = array("","Oth","Tlr","Rec","Fsr");
$Inum = $_SESSION['Clnt'];
$Lnum = $_SESSION['Locn'];
$Name = mysql_real_escape_string($_POST['Name'],$Link);
$Posn = $Ptypes[$_POST['Posn']]; // numeric $_POST from dropdown select
$Typ = 0 + $_POST['Type']; // numeric user input
$D = date("Y-m-d") . " 00:00:00"; // date only used in satff records
$Query = "UPDATE Precord SET Get=$Typ,Nused='$Posn',Name='$Name' WHERE id=" . $_POST['id'];
}
produces thie following SQL statement, which blanks the Nused field.
Code: Select all
UPDATE Precord SET Typ=1,Nused='Rec',Name='William' WHERE id=20968
Can anyone see a difference which would cause that? I should note,
they are in the same script. One runs or the other one does.