Jump to content

Date and Time issues


BelowZero

Recommended Posts

I'm having some trouble understanding how to use date and time when updating my database.

The table is already populated with Date and Time fields in date and time format. I need to update the table based on the date and time, but I can't make it work. I tested all the variables and they are being sent correctly.

I'm pretty sure the problem lies in how I'm trying to match the Date and Time fields with $dateID and $timeID in the WHERE part of the query, but I'm not sure how to fix that!

<?php	

include("opendatabase.php");

$size = count($_POST['player1']);
$i=0;
$thisyear = date("Y");

while ($i < $size)
     {
     $dateID = $_POST['date'][$i];
     $timeID = $_POST['time'][$i];
     $player1 = ($_POST['player1'][$i]);
     $player2 = ($_POST['player2'][$i]);
     $player3 = ($_POST['player3'][$i]);
     $player4 = ($_POST['player4'][$i]);
     $player5 = ($_POST['player5'][$i]);

mysql_query("
UPDATE Daysheets$thisyear
SET 
        Player1='$player1',
        Player2='$player2',
        Player3='$player3',
        Player4='$player4',
        Player5='$player5'

WHERE Date = '$dateID'
AND Time = '$timeID' ");
     $i++;
}

header("Location: /teetimes/publicteetimes.php?teetimedate=$dateID");

mysql_close($con)

?>

Any help appreciated!

I should also mention that whenever I run this query it erases anything that was previously entered in the database except the date and time columns...

Link to comment
Share on other sites

 

Have you check for a mysql_error()?

 

A nice trick I like to do when something looks like it should working but isn't is just echo out the whole query and check everything looks ok.

 

<?php   

include("opendatabase.php");

$size = count($_POST['player1']);
$i=0;
$thisyear = date("Y");

while ($i < $size)
     {
     $dateID = $_POST['date'][$i];
     $timeID = $_POST['time'][$i];
     $player1 = ($_POST['player1'][$i]);
     $player2 = ($_POST['player2'][$i]);
     $player3 = ($_POST['player3'][$i]);
     $player4 = ($_POST['player4'][$i]);
     $player5 = ($_POST['player5'][$i]);

echo <<<_END
mysql_query("
   UPDATE Daysheets$thisyear
   SET 
        Player1='$player1',
        Player2='$player2',
        Player3='$player3',
        Player4='$player4',
        Player5='$player5'

   WHERE 
    Date = '$dateID'   AND Time = '$timeID' 
");
<br/><br/>
_END;

     $i++;
   }


//header("Location: /teetimes/publicteetimes.php?teetimedate=$dateID");

mysql_close($con)

?>

 

Link to comment
Share on other sites

yes, smerny.

I put the semi-colon in but am still getting the unexpected end.

Beings that this file is the result of an include() in another file, could the error be outside the <<<_end ..._end?

I don't see anything missing in the query. Could the date and time comparisons be the issue?

Link to comment
Share on other sites

This is the code I now have:

<?php	

include("opendatabase.php");

$size = count($_POST['player1']);
$i=0;
$thisyear = date("Y");

while ($i < $size)
     {
     $dateID = $_POST['date'][$i];
     $timeID = $_POST['time'][$i];
     $player1 = ($_POST['player1'][$i]);
     $player2 = ($_POST['player2'][$i]);
     $player3 = ($_POST['player3'][$i]);
     $player4 = ($_POST['player4'][$i]);
     $player5 = ($_POST['player5'][$i]);


echo <<<_END

mysql_query("
UPDATE Daysheets$thisyear
SET 
        Player1='$player1',
        Player2='$player2',
        Player3='$player3',
        Player4='$player4',
        Player5='$player5'

WHERE Date = '$dateID'
AND Time = '$timeID' ");
<br/><br/>
_END;

     $i++;
}


//header("Location: /teetimes/publicteetimes.php?teetimedate=$dateID");

mysql_close($con);

?>

The error checking still results in an unexpected end.

Link to comment
Share on other sites

Okay.

Well after now running the script I am getting a whole page full of info.

Every query in the while loop is displayed.

Does this mean each line contains an error?

If so, then the problem has to be back to the date and time issue.

 

No.

 

You have not run the query. you have simply echo'd each query that would have been.

 

Now check the queries are what you expected them to say..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.