I'm having a really strange issue with what I believe is a simple query. This was code I used to learn PHP a few years ago and was trying to repurpose it for a really simple time tracking application. When time permits, I'll work on making a new version with mysqli, but in the meantime I just want to get it working. I'm still learning, so it's not easy for me.
When a form posts, I'm basically gathering the data and trying to 1) update an existing value in one table based on submitted information and 2) create a new row in another table to store all entered values from the previous form.
Here's how I had written it:
<?php $uid = $_COOKIE["uid"]; $cid = $_POST['customer_id']; $pid = $_POST['project_id']; $hoursAdded = $_POST['hoursAdded']; mysql_query("UPDATE projects SET hours=hours+'$hoursAdded' WHERE id='$pid'") or die(mysql_error()); mysql_query("INSERT INTO hours (id,uid,pid,cid,userhours) VALUES ('','$uid','$pid','$cid','$hoursAdded')") or die(mysql_error()); ?>
Everything works fine, but occasionally the SECOND mysql_query statement doesn't actually INSERT anything into the hours table. The First query always writes, but the second sometimes just doesn't do anything - no errors - nothing.
Essentially, the sum of the hours submitted in the HOURS table should equal the TOTAL hours updated in the projects table. Because the second query sometimes doesn't write, I end up with a project that has, for example, 200 TOTAL hours, and the sum of all hours for that project in the HOURS table totalling much less than 200.
Any ideas what's going on? Why would it sometimes write and other times not?
Thanks and sorry if the problem is obvious. This is still new to me.