Timestamp

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sirstrumalot
Forum Commoner
Posts: 27
Joined: Mon May 18, 2009 10:26 pm

Timestamp

Post by sirstrumalot »

Okay, so i've read over a few things and i'm a bit lost how to do this.

I have an input mask that is setting an input mask for the users. It's perfect because they can type in 1230 and it was come out as 12:30. From there, they choose a dropdown box for AM/PM. It's perfect. Ideally, I don't want to change it.

I am entering the data in as such:

Code: Select all

mysql_query("INSERT INTO missedVisit (missed_aptTime) VALUES ('".trim(addslashes($_POST['missed_aptTime']))."')");  
And if it needs to be updated later, we can go back and query this way:

Code: Select all

$updateSQL = sprintf("UPDATE missedVisit SET missed_aptTime=%s WHERE missed_id=%s",
                       GetSQLValueString(trim(addslashes($_POST['missed_aptTime'])), "text"),
                       GetSQLValueString(trim($_POST['missed_id']), "int"));
 
  mysql_select_db($database_contacts, $contacts);
  $Result1 = mysql_query($updateSQL, $contacts) or die(mysql_error());
-----
Now, the PHP:

Code: Select all

<input name="missed_aptTime" type="text" class="text input_mask mask_time" id="missed_aptTime" size="6" maxlength="5" value="<?php echo $row_missed['missed_aptTime']; ?>"/>
                <select name="missed_aptTimeAMPM" id="missed_aptTimeAMPM">
                <option value=" " selected="selected"> </option>
                <option value="AM"<?php if (!(strcmp("AM", $row_missed['missed_aptTimeAMPM']))) {echo "selected=\"selected\"";} ?>>AM</option>
                <option value="PM"<?php if (!(strcmp("PM", $row_missed['missed_aptTimeAMPM']))) {echo "selected=\"selected\"";} ?>>PM</option>
                </select>
Of course there are other fields in the form and database, but I shortened it for good measure.
The issue at hand is: I enjoy the input mask and it's ease of use. I would like it be able to insert this time into the database. If I need to modify the database fields, I can. But right now, when I insert this, I get a result for 12:30 in the field as 12 or for 05:30 as 05. It only goes to the colon.

I am aware that this needs to conform to TIME or TIMESTAMP or DATETIME, but I don't want to severely modify my stinkin' input mask and form layout.
Anyone know what I can do to make this happen? If it needs to be a string, that's fine, but how do I do it? If I need to convert the HH:MM to HH:MM:SS, i'm okay with that and changing the field type too, but how? I'm lost.

Much thanks appreciated.
andycain
Forum Newbie
Posts: 19
Joined: Thu Jul 31, 2008 5:21 pm

Re: Timestamp

Post by andycain »

Hi.

Does your input mask directly insert a colon or does it add the ascii code &#58; ?

Try modifiying the input mask to change it to this.

Ie.

If a user enters 1230 the input mask currently changes the inputted time to 12:30

Modify the input mask to change the inputted time from 1230 to 12&#58;30

This will eliminate the colon. This could be something to do with characters being escaped.

Bit of a longshot but it must be the colon which is throwing the script.

Give that a try.
sirstrumalot
Forum Commoner
Posts: 27
Joined: Mon May 18, 2009 10:26 pm

Re: Timestamp

Post by sirstrumalot »

I found the issue. It simply was set as the wrong data type.
Post Reply