Jump to content

Inserting time stamp broke my database:


J450n

Recommended Posts

I have a MySQL DB and everything is working perfectly.  I wanted to expand it with a time stamp entry.  I added all the required code and now cannot update the UPDATE querywhen exiting my app.

I deleted all the code associated with the time stamp and everything works as expected.

Is there something I do not know about time stamps?  I have used it before with C# .net with no issues at all.

I'm not a pro PHP guy and have no clue why it would break the UPDATE query.

Link to comment
Share on other sites

I deleted it as it didn't work.  I should have just commented it out but I was pissed.

$timeStamp = $_POST["timeStamp"];

$updatequery = "UPDATE userData SET timeStamp= " . $timeStamp. " WHERE GUID = '" . $LoggedIn_guid . "';";

In the database I had that row set to varchar  not TimeStamp.

Link to comment
Share on other sites

A time stamp (eg 2019-12-15 19:02:00) is a string value and should therefore be inside single quotes in your query.

(This would be the same in C# as it is purely SQL related, not C# or PHP).

You should (in either language) be using prepared queries and not embedding variables in the query. For example (using PDO)

$stmt = $conn->prepare("UPDATE userData SET timestamp = ? WHERE GUID = ?")
$stmt->execute([ $timeStamp, $LoggedIn_guid ]);

 

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.