In my defense, the actual program is longer than this …
// Create variables ;
$id = strtoupper(trim($_REQUEST[‘id’])) ;
$application_date = $_REQUEST[‘yr_of_apply’] . “-” . $_REQUEST[‘month_of_apply’] .”-“. $_REQUEST[‘day_of_apply’] ;
$assessment_date = $_REQUEST[‘yr_of_assess’]. “-” . $_REQUEST[‘month_of_assess’] .”-“. $_REQUEST[‘day_of_assess’] ;
$eligibility_date = $_REQUEST[‘yr_eligible’].”-“.$_REQUEST[‘month_eligible’] .”-“. $_REQUEST[‘day_eligible’] ;
$ipe_date = $_REQUEST[‘yr_ipe’].”-“.$_REQUEST[‘month_ipe’] .”-“. $_REQUEST[‘day_ipe’] ;
$notify_rights = $_REQUEST[‘notify_rights’] ;
$vocational_goal = $_REQUEST[‘vocational_goal’] ;
// Get user info ;
$result = mysql_query(“UPDATE clients SET notify_rights = ‘$notify_rights’, vocational_goal = ‘$vocational_goal’ ,
application_date = ‘$application_date’ , assessment_date = ‘$assessment_date’
WHERE id = ‘$id'”)
or die(mysql_error()) ;
echo “<p>Your record was updated successfully.</p>” ;
So, it didn’t work. All I wanted to do was connect to the SQL database, find the client’s id and update that record with the application information.
First problem I found was that I had tested this with a much smaller file with just a few columns and in my UPDATE statement it still had the table ‘test’ instead of ‘clients’. I was getting an error that said there was “an error in my SQL code”. Which is true. Since the table did exist, I wasn’t getting an error saying it wasn’t found. Ok, I fixed that
Second problem, the dates were actually entered in three different fields to make it easier for error checking – your year has to be within the current fiscal year, month between 1 and 12, no entering April 31. However, I needed those to BE dates for analyses we plan later. So, I just created the date variables. Problem solved.
Third problem, I realized I really did not want the password and other information required for connection in this program where anyone could see it. There is no personally identifiable information in here, but it’s just a bad habit to have your passwords and other data hanging out there. Hence the statement to require the connect.php script .
Fourth problem, the ID variable is not a number. It can be something like ABJ-001 , so it doesn’t match if it the case is not the same or if there are spaces. The strtoupper and trim functions fixed that.
Fifth problem, some of the dates were blank. I looked at them over and over to see if I had mismatched quotes . I even actually deleted and re-typed the statements. Nope, still, some of the dates were there and others were blank. Maybe they weren’t date format in the table definition? Nope, I checked and the missing dates and the dates that updated properly were all defined as the same format.
Well, maybe you spotted it already … As I said in the first problem, I had originally created and tested the script with a table named ‘test’ that had just a few columns. When I switched to my client table, I had forgotten to add all of the columns to the UPDATE statement. The problem wasn’t in creating the eligibility and ipe date fields. The problem was that I left those fields off of the update statement so they were never getting updated. Everything went through fine, I got a message saying my record was updated – because as far as PHP was concerned, it wasn’t an error. Maybe I only wanted to update some of the columns.
The moral of the story is this: Sometimes the problem is the code you DIDN’T write.