I’m working on a browser based scheduling application and have run into an interesting problem.
So I’ve got a schedule (staff names and their shifts, let’s say) appearing in the browser that was loaded from a database table. No problems there. The schedule data was initially created from an SQL file holding all my tables and imported directly into the server through phpMyAdmin. I click on a button in the browser to run calculations for a certain feature of the application and everything calculates beautifully.
Now, say I type over employee name Ryan D in the spreadsheet on the browser and replace it with Ryan D (yes, the exact same name; I’m trying test that the calculation succeeds again using the same data set but after a manual change has been made to the spreadsheet). I save the data to the server by clicking a save button. The save code (a PHP file) gets the data from the HTML table and creates an SQL statement that executes fine and uploads the changes to the schedule table in the database. I check phpMyAdmin after and sure enough, the data was saved: my table id numbers of the primary key have incremented but everything else (names and shifts) looks the same as it did originally…because all I did was retype Ryan D over itself.
I click on the button to run the calculations and the schedule data from the database table feed back into the code the same as before, but this time the calculations do not consider the row containing Ryan D, even though in the error_log I’m able to print out all the array values used in the calculations and see that everything is exactly the same as it was before. Super weird!
This is day 2 of dealing with the problem. I thought maybe the data was feeding in from the original SQL file differently than the data feeding from the browser via the SQL statement from the save button code (the PHP file). But that can’t be the case because I can click the save button and then rerun the calculations as many times as I want and it always works fine…as long as I don’t make any changes to the schedule.
Is there something I’m missing in how strings may be formatted behind the scenes and are being interpreted by PHP? The original schedule data that runs correctly in the calculations was imported straight from an SQL file. I even rewrote the code to load from a PHP file, and it too worked fine. So the only thing different that is happening is that changes to the schedule come from manual changes to values in an HTML table cell (td); the new values feed to a PHP file via the POST method and are then sent/saved to the database table thru an SQL query statement in that PHP file. But this doesn’t make sense to me either because the database table is getting updated with HTML table values anyway (using SQL INSERT) each time I save because I’m actually wiping the database table values clean (with SQL DELETE) beforehand.
I’m at a total loss…
On a positive note, I’ve been working on stringing together some mighty fine profanities.