Jump to content
#StayAtHome ×
J450n

Inserting time stamp broke my database:

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.

Share this post


Link to post
Share on other sites
34 minutes ago, J450n said:

and have no clue why it would break the UPDATE query.

neither do we since we cannot see the problematic code from where we are sitting.

Share this post


Link to post
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.

Share this post


Link to post
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 ]);

 

Share this post


Link to post
Share on other sites

Mainly, but it also saves having to escape string data too (For example, if you were trying to add "O'Reilly" as a name value.

Share this post


Link to post
Share on other sites

Oh I see.  Thank you.  Now I'll know how to fix that problem when I hit it..lol

Share this post


Link to post
Share on other sites

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.