Results 1 to 7 of 7
Nov 8, 2011, 10:09 #1
- Join Date
- Oct 2009
- 0 Post(s)
- 0 Thread(s)
Checking fields for values and adding dates
Up to five dates and day/night values can be stored per user in total, i.e I have set up these fields in the mySQL users table: Date1, DayNight1, Date2, DayNight2, Date3, DayNight3, Date4, DayNight4, Date5, DayNight5.
When the form is submitted, I want it to populate Date1 and DayNight1, but ONLY if there's nothing already in those fields. If there is, then it should check Date2 and DayNight2, and so on until all fields have been checked. If all fields are full, it will echo a message to say so, and direct the user to a separate page / form where they can delete values as appropriate.
If Date1 and DayNight1 are empty, it should just run the INSERT statement as normal. If they contain values, but Date2 and DayNight2 don't, then run the INSERT statement but with values being entered into the fields for Date2 and DayNight2 instead. So I guess there need to be 4 different INSERT statements in the code depending on the condition of the Date / Daynight fields.
Getting a bit confused with how to put all this into the code though. I've got as far as this but I know it won't work as is (I need to find a way of adding in the other INSERT statements but can't see how)
echo '<p>All your date slots are currently full. <a href="deleteavailabledates.php">Click here</a> to remove some of your date slots.</p>';
// Build SQL Query
$query = "INSERT INTO users (DateAvailable5, DayOrNight5) VALUES ('$dateavailable', '$dayornight') WHERE Username LIKE '$user'"; // specify the table and field names for the SQL query
if($result = mysql_query($query))
echo "ERROR: ".mysql_error();
Any ideas?... as this seems quite complex at the moment but probably doesn't need to be.
By the way, the calendar / date picker doesn't allow multiple dates to be added at the same time (and even if it did, obviously this could make it messy when inputting values from the input in the form, into the db table date fields)