-1

currently I'm getting the error stated above using thise code:

$Tijd = date_create($_POST ["Tijd"]);
$Tijd->format(\DateTime::ISO8601);

$result = mysql_query ("SELECT Voorstellingsnummer FROM voorstelling v WHERE Tijd = '$Tijd' AND v.Voorstellingsnummer NOT IN(SELECT r.Voorstellingsnummer FROM reserveringen r WHERE r.Voorstellingsnummer = v.Voorstellingsnummer GROUP BY r.Voorstellingsnummer HAVING COUNT(*) >= 50) AND Vestigingsnaam = '" . $_SESSION["geselecteerdvestiging"] . "' AND Filmnaam = '" . $_SESSION["geselecteerdfilmnaam"] . "';", $db);

Object of class DateTime could not be converted to string

the error happens in the $result = etc...

Full error: Catchable fatal error: Object of class DateTime could not be converted to string in E:\xampplite\htdocs\havo5groep2\reserveren.php on line 60

I use this form to get the post data

                            echo "<form action='reserveren.php' method='post'>
                            <H3>Kies een Tijd</H3><br>
                            <select name='Tijd'> ";
                        while ($row = mysql_fetch_array($_SESSION["Tijd"])) {
                            echo "<option value='" . $row['Tijd'] ."'>" . $row['Tijd'] ."</option>";
                        }
                        echo "</select>
                            <input type='submit' name='Reserveer' value='Reserveren'>
                            </form>";

I get the values from $row from the following query:

        $resultaat = mysql_query ("SELECT Tijd FROM voorstelling v WHERE v.Voorstellingsnummer NOT IN(SELECT r.Voorstellingsnummer FROM reserveringen r WHERE r.Voorstellingsnummer = v.Voorstellingsnummer GROUP BY r.Voorstellingsnummer HAVING COUNT(*) >= 50) AND Vestigingsnaam = '" . $_SESSION["geselecteerdvestiging"] . "' AND Filmnaam = '" . $_SESSION["geselecteerdfilmnaam"] . "';", $db);
    $_SESSION["Tijd"] = $resultaat;

the value of Tijd in the select are all datetime records.

So my question is how do I succesfully get the value form the select form to convert into a timedate that I can use in my query

closed as off-topic by Vérace, mustaccio, Marcello Miorelli, Michael Green, dezso Apr 4 at 14:53

If this question can be reworded to fit the rules in the help center, please edit the question.

  • Could you please "strip out" all of the PHP code in your question. Although many here have a programming background, not everybody has done PHP. It's difficult (for me anyway) to focus on the core database issue to hand. Run your query from the command line, show us the results and we'll work from there. – Vérace Mar 30 at 10:18
  • The problem is that without showing the php code the code is not readable. I know this question is better for stackoverflow but I can't post on that website anymore due me not having a score high enough to do so – Yvalson Dronkers Mar 30 at 10:25
  • Eh? People with a rep of 1 can post questions - it's comments for people with low reps that are the problem! But, you can always comment on your own question. Not being able to post on SO is no reason to post off-topic questions here. As I've said, you can't assume programming ability/experience here - plus, until you've established that it's a database (and not a coding) issue, then AFAICS, your question is off-topic. The burden of proof is on you, and you even say yourself that the question is better on SO. Get a new identity, post to SO and follow their guidelines and I'm sure no prob! – Vérace Mar 30 at 10:37
  • I thought creating a new account on SO was prohibited but will do then Thank you. the weird thing is my rep on SO is 26 so I just don't get it but thank you for the tip – Yvalson Dronkers Mar 30 at 10:44
  • You could try and contact a moderator to find out what the issue is. I've taken a quick look and your questions don't seem bad (at all) to me. Try flagging one of your own questions and ask what the story is - or go to the meta site? Not sure what the policy is here - check this out. – Vérace Mar 30 at 10:48
0

As has been intimated in the comments quite possibly is not a database isue, in fact the error you are receiving is generated from PHP.

The error is caused by a slight misunderstanding of what datetime->format() does.

This does not change the format the date and time is stored in rather it returns the date and time in that format immediately (datetime->format() documentation)

To correct this in your code you need to capture the result of "$Tijd->format(\DateTime::ISO8601);" in another variable such as:

$Tijd = date_create($_POST ["Tijd"]);
$formattedTime = $Tijd->format(\DateTime::ISO8601);

You can then use this in the SQL such:

$result = mysql_query (
      "SELECT Voorstellingsnummer
      FROM voorstelling v
      WHERE Tijd = '$formattedTime' AND
      v.Voorstellingsnummer NOT IN(
         SELECT r.Voorstellingsnummer
         FROM reserveringen r
         WHERE r.Voorstellingsnummer = v.Voorstellingsnummer
         GROUP BY r.Voorstellingsnummer
         HAVING COUNT(*) >= 50
      ) AND
      Vestigingsnaam = '" . $_SESSION["geselecteerdvestiging"] . "' AND
      Filmnaam = '" . $_SESSION["geselecteerdfilmnaam"] . "';",
   $db
);
  • I fixed the problem using another method but yours also works so I selected it. – Yvalson Dronkers Apr 1 at 6:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.