MySQL query or condition to fetch "1970-01-01" date value in the table cell |
MySQL query or condition to fetch "1970-01-01" date value in the table cell |
shankar from vizag |
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 |
CharlesEF |
Dec 28 2023, 05:33 PM
Post
#2
|
Programming Fanatic Group: Members Posts: 1,984 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
I have not heard from you about the test results. But try this:
CODE <?php session_start(); $con=mysqli_connect("localhost", "root", "", "test"); if(isset($_POST['save'])) { $name=$_POST['name']; $dob=empty($_POST['dob']) ? "NULL" : "'{$_POST['dob']}'"; $query="INSERT INTO date(name,date) VALUES('$name', $dob)"; $query_run = mysqli_query($con, $query); $_SESSION['status']="Date values inserted"; } else { $_SESSION['status']="Date values Inserting failed"; } ?> |
shankar from vizag |
Dec 31 2023, 07:58 AM
Post
#3
|
Advanced Member Group: Members Posts: 202 Joined: 18-June 13 Member No.: 19,316 |
I have not heard from you about the test results. But try this: CODE <?php session_start(); $con=mysqli_connect("localhost", "root", "", "test"); if(isset($_POST['save'])) { $name=$_POST['name']; $dob=empty($_POST['dob']) ? "NULL" : "'{$_POST['dob']}'"; $query="INSERT INTO date(name,date) VALUES('$name', $dob)"; $query_run = mysqli_query($con, $query); $_SESSION['status']="Date values inserted"; } else { $_SESSION['status']="Date values Inserting failed"; } ?> Hi Charles Let me wish one and all of this forum a very happy new year in advance Its my hobby to design in PHP MYSQL. I learnt from the online resources like our forum, youtube videos hence you may find lots of errors in my approach. my happiness of putting down the above error evaporates with a fresh error with select query to display records. Whereever NULL values in the table cell, select query fetching and displaying as 1970-01-01. The following is the code, $conn = new mysqli("localhost", "root", "", "test"); $sql="select * from date"; $res=$conn->query($sql); while($row=$res->fetch_assoc()){ ?> <tr> <td> if(is_null($row['dob'])){ echo '--'; }else{ echo 'date("d-m-Y",strtotime($row['dob']))'; }?> </td> </tr> With the above If condition, the display of 1970-01-01 is stopped where there is a NULL in table cell but when there is a date, that also showing as blank. Please guide me to overcome this issue. Regards This post has been edited by shankar from vizag: Dec 31 2023, 07:59 AM |
Lo-Fi Version | Time is now: 25th September 2024 - 04:40 PM |