1

I keep getting this error:

"Catchable fatal error: Object of class DateTime could not be converted to string"

From this code:

<?php
   $value_startTime = new DateTime();
   $value_startTime->setTime($value_HourStart,$_POST['TextBoxStartMin'],0);

   $value_endTime = new DateTime();
   $value_endTime->setTime($value_HourEnd,$_POST['TextBoxEndMin'],0);

   $query_InsertJob="INSERT INTO job (jobDesc,timeStart,timeEnd)
   VALUE ('$_POST[TextAreaProblem]','$value_startTime','$value_endTime')";
?>

These variables can have values from 00 to 23: $value_HourStart $value_HourEnd

These variables can have values from 00 to 59: $_POST['TextBoxStartMin'] $_POST['TextBoxEndMin']

I am having no trouble with: $_POST[TextAreaProblem]

What is it that I am doing wrong?

2 Answers 2

1

You need to convert those DateTime objects into strings for use in the query.

Try something like this (PDO example because I can't abide encouraging people to use the mysql_* functions)

$stmt = $db->prepare('INSERT INTO job (jobDesc, timeState, timeEnd) VALUES (?, ?, ?)');
$stmt->execute(array(
    $_POST['TextAreaProblem'],
    $value_startTime->format('H:i:s'),
    $value_endTime->format('H:i:s')
));
Sign up to request clarification or add additional context in comments.

Comments

0

$value_startTime and $value_endTime are objects. Try it with $value_startTime->getTimestamp().

$query_InsertJob="INSERT INTO job (jobDesc,timeStart,timeEnd) VALUE ('$_POST[TextAreaProblem]','".$value_startTime->getTimestamp()."','"$value_endTime->getTimestamp()."')";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.