The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> MySQL query or condition to fetch "1970-01-01" date value in the table cell
shankar from vizag
post Dec 9 2023, 08:33 PM
Post #1


Advanced Member
****

Group: Members
Posts: 202
Joined: 18-June 13
Member No.: 19,316



Greetings

I have a mysql table with date column cell. At the time input from the php page, if a date type input left blank which is saving 1970-01-01 as the cell value.

When I use select query to display records, those particular fields displaying 1970-01-01.

Could anyone help me either in saving the empty date field as 1970-01-01 as blank

or

a condition to display a blank field in the php page by the select query when the cell value contains 1970-01-01.

Regards
shankar
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
CharlesEF
post Dec 22 2023, 11:39 PM
Post #2


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Your current code is wide open to SQL injection attacks. NEVER use any user supplied data directly in your code. You use 'mysqli' and you should be using parameterized queries. See here for an example. If you refuse to take my advice you can try:
CODE
$dob=empty($_POST['dob']) ? null : $_POST['dob'];

You're still trying to insert a blank date right?

This post has been edited by CharlesEF: Dec 22 2023, 11:42 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
shankar from vizag
post Dec 23 2023, 01:18 AM
Post #3


Advanced Member
****

Group: Members
Posts: 202
Joined: 18-June 13
Member No.: 19,316



QUOTE(CharlesEF @ Dec 23 2023, 10:09 AM) *

Your current code is wide open to SQL injection attacks. NEVER use any user supplied data directly in your code. You use 'mysqli' and you should be using parameterized queries. See here for an example. If you refuse to take my advice you can try:
CODE
$dob=empty($_POST['dob']) ? null : $_POST['dob'];

You're still trying to insert a blank date right?


Thank you charles for your guidance.

I will try with the above line of code and come back to you.

Regards
Shankar
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic
shankar from vizag   MySQL query or condition to fetch "1970-01-01" date value in the table cell   Dec 9 2023, 08:33 PM
CharlesEF   If you have a MySQL DATE or DATETIME column and it...   Dec 9 2023, 11:10 PM
CharlesEF   Or, you could set the column as 'Default NULL...   Dec 10 2023, 03:29 AM
shankar from vizag   Or, you could set the column as 'Default NULL...   Dec 12 2023, 01:45 AM
CharlesEF   Or, you could set the column as 'Default NUL...   Dec 12 2023, 02:08 AM
CharlesEF   Since you posted no code all I can do is show you ...   Dec 12 2023, 09:33 PM
shankar from vizag   Since you posted no code all I can do is show you...   Dec 22 2023, 08:38 PM
CharlesEF   Your current code is wide open to SQL injection at...   Dec 22 2023, 11:39 PM
shankar from vizag   Your current code is wide open to SQL injection a...   Dec 23 2023, 01:18 AM
CharlesEF   It's been many years since I've used mysql...   Dec 23 2023, 04:29 AM
shankar from vizag   It's been many years since I've used mysq...   Dec 23 2023, 08:28 PM
CharlesEF   Try this and let me know about error messages. ...   Dec 24 2023, 01:13 AM
shankar from vizag   Try this and let me know about error messages. [c...   Dec 24 2023, 10:47 PM
shankar from vizag   [quote name='CharlesEF' post='146837' date='Dec 2...   Dec 25 2023, 04:06 AM
CharlesEF   You should run a few tests. Don't use the ...   Dec 24 2023, 03:06 AM
CharlesEF   I'm glad the PDO version works. But, I'd ...   Dec 25 2023, 04:34 PM
CharlesEF   I have not heard from you about the test results. ...   Dec 28 2023, 05:33 PM
shankar from vizag   I have not heard from you about the test results....   Dec 31 2023, 07:58 AM
CharlesEF   You've posted new code about reading a databas...   Dec 31 2023, 02:54 PM


Reply to this topicStart new topic
3 User(s) are reading this topic (3 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 23rd May 2024 - 04:51 AM