need help on a datetime query submission

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
robscriven
Forum Newbie
Posts: 6
Joined: Sun Jan 08, 2006 5:38 pm

need help on a datetime query submission

Post by robscriven »

hawleyjr | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read: :arrow: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi,

I have some code i am trying to modify which inserts a booking into a mysql database. People book in blocks of 5 so there should be 5 bookings automatically created at the same time every 7 days. The date needs to be submitted in YYYY-MM-DD hh:mm:ss format. If i comment out the ($date = date("Y-m-d h:i:s", mktime($hour, $min, $second, $month, $day + 7, $year));) line there are 5 records created all with the same date and when i uncomment it the code doesnt work so Im pretty sure this is the line playing up. I've tried playing around with it but have had no luck, any help would be gratefully recieved.

Thanks,

Rob

Code: Select all

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

$date = GetSQLValueString($_POST['lesson_datetime'], "date");

for ($i = 0; $i < 5; $i++)
{

$year = substr($date, 0, 4);
$month = substr($date, 5, 2);
$day = substr($date, 8, 2);
$hour = substr($date, 11, 2);
$min = substr($date, 14, 2);
$second = substr($date, 17, 2);

$date = date("Y-m-d h:i:s", mktime($hour, $min, $second, $month, $day + 7, $year));

  $insertSQL = sprintf("INSERT INTO booking (bookingid, teacherid, studentid, roomid, lessontypeid, lesson_datetime, cancel) VALUES (%s, %s, %s, %s, %s, %s, %s)",
  
                       GetSQLValueString($_POST['bookingid'], "int"),
                       GetSQLValueString($_POST['teacherid'], "int"),
                       GetSQLValueString($_POST['studentid'], "int"),
                       GetSQLValueString($_POST['roomid'], "int"),
                       GetSQLValueString($_POST['lessontypeid'], "int"),
                       $date,
                       GetSQLValueString($_POST['cancel'], "text"));

  mysql_select_db($database_connection, $connection);
  $Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());

}
}

hawleyjr | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read: :arrow: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you need to use GetSQLValueString() on $date.
robscriven
Forum Newbie
Posts: 6
Joined: Sun Jan 08, 2006 5:38 pm

Post by robscriven »

hi,

i thought i'd tried that but i'd obviously changed a couple of other things that caused it not to work, but its okay now...cheers!
Post Reply