Skip to content
Advertisement

Update a NULL datetime column from PHP form

So I’ve been trying possible solutions but didn’t get any success. I wanted to UPDATE the “timeOut” column (which has a NULL value) at the end of the day. I wanted to change it from NULL to whatever is filled on the form. Here’s my php code:

JavaScript

and here’s my php form

JavaScript

Advertisement

Answer

You have two issues. The first is that your debugging methods are failing you, you have header('location:record.php') twice, both for an error and success. Additionally, after every header you should have an exit so the code stops firing. As the code currently is written even with the error state the update still fires but (error #2) since $id is set to NULL because your form has no id value the where matches no records and no update occurs.

So your PHP should be:

JavaScript

and then your HTML should be (presuming these are on the same page, if not change $id to the id variable):

JavaScript

alternatively to get in POST

JavaScript

Additionally see commented out header calls. I would use those and on record.php look at $_GET['status'] to see what occurs.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement