variables $rand_start, $rand_misc, $rand_end are inserted in mysql table.
most of the time, values like 6,8,12 is inserted which is what I want, but sometimes values like 346261932 are inserted in rand_misc and rand_end fields. It never happen with rand_start field.
Fields in the database are int(11)
$SECS_DURATION variable should be time in seconds, but I don’t know how to declare it to be so.
Inserting values like 346261932 in my table, cause my script to halt and to stop to work.
Anyone can help me to ensure that I will always insert values in seconds (1-59) in my table? What should I do with $SECS_DURATION variable so I can ensure that time in seconds will be inserted in my table?
You need to see what the value of $SECS_DURATION is when the script is going wrong. What range of values would you expect for $SECS_DURATION? Perhaps filter it before you rand() lines with something like:
If I could just ensure that $SECS_DURATION has format of seconds I will be fine. This value is entered by user, and it may be 90,60,45…or some other value. So I need to ensure that result from the calculation
Aha… Yeah, trying to insert a negative number into an unsigned field will roll over to the the highest possible number. So you must make sure the second number cannot be lower than the higher.
So, if $SECS_DURATION is 4 or less, negative numbers will be in the range.
I think you are going about this all wrong. If you know what the duration is then all is left is to randomly choose a start time - the end time will be a fixed interval after the start. If the duration is variable, store that.