MySQL Forums
Forum List  »  PHP

Problem storing dates!
Posted by: Raymond Jender
Date: June 18, 2021 08:08AM

I am new to PHP and mysql so have mercy on me.
I have two dates that I need to store, a current date and
a due date. Here are the particulars:

My HTML:

<form id="form_27395" class="appnitro" method="POST" action="insert.php">
.
.
.
<label for="currentdate">Today's Date:&nbsp;</label><input id="currentdate" type="date" name="currentdate" Required /> &nbsp;&nbsp;<label for="surveyduedate"><span style="color:red">Survey Due Date:</span>&nbsp;</label><input id="surveryduedate" type="date" name="surveyduedate" Required />

My PHP:

$currentdate = $_POST['currentdate'];
echo nl2br("currentdate = $currentdate\n");
$sql = "INSERT INTO `orderform` (currentdate) VALUE ($currentdate)";

if(mysqli_query($link, $sql)){

echo nl2br("currentdate $currentdate record inserted successfully.\n");

} else {

echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

$surveyduedate = $_POST['surveyduedate'];
echo nl2br("surveyduedate = $surveyduedate\n");
$sql = "INSERT INTO `orderform` (surveyduedate) VALUE ($surveyduedate)";

if(mysqli_query($link, $sql)){

echo nl2br("surveyduedate $surveyduedate record inserted successfully.\n");

} else {

echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

My orderform desc:

mysql> desc orderform;
+---------------+--------------------------+------+-----+----------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------------------+------+-----+----------+----------------+
| id | int | NO | PRI | NULL | auto_increment |
| jobnumber | int | NO | | 21060000 | |
| year | int | NO | | 21 | |
| month | int(2) unsigned zerofill | NO | | 06 | |
| currentdate | varchar(10) | YES | | NULL | |
| surveyduedate | varchar(10) | YES | | NULL | |
+---------------+--------------------------+------+-----+----------+----------------+
6 rows in set (0.01 sec)

My echo outputs: (you can ignore everything up to the current and surveydue dates:

row = 0009

Initial idx = 0009
jobyear = 21
currentyear = 21
jobmonth = 06
currentmonth = 06
Index1 = 0009
Index2 = 0010
idx 0010 record inserted successfully.
Index3 = 0010
updatejobnumber3 = 21060010
Jobnumber 21060010 record inserted successfully.
currentdate = 2021-06-18
currentdate 2021-06-18 record inserted successfully.
surveyduedate = 2021-06-19
surveyduedate 2021-06-19 record inserted successfully.

My orderform table after execution:

mysql> select * from orderform;
+----+-----------+------+-------+-------------+---------------+
| id | jobnumber | year | month | currentdate | surveyduedate |
+----+-----------+------+-------+-------------+---------------+
| 1 | 21060001 | 21 | 06 | 2021-06-17 | 2021-06-20 |
| 2 | 21060004 | 21 | 06 | 2021-06-17 | 2021-06-30 |
| 3 | 21060005 | 21 | 06 | 2021-06-17 | 2021-06-30 |
| 4 | 21060006 | 21 | 06 | 2021-06-17 | 2021-06-30 |
| 5 | 21060007 | 21 | 06 | 2021-06-17 | 2021-06-30 |
| 6 | 21060010 | 21 | 06 | NULL | NULL |
| 7 | 21060000 | 21 | 06 | 1997 | NULL |
| 8 | 21060000 | 21 | 06 | NULL | 1996 |
+----+-----------+------+-------+-------------+---------------+
8 rows in set (0.00 sec)

As you can see the currentdate and surveryduedate's are munged
in rows 6-8, even though PHP says the correct dates were inserted?
Rows 1-7 were because I had those dates as DEFAULT
while I was troubleshooting.

The NULL and DEFAULT are somewhat confusing to me.

Any ideas what is going on?

Thanks,

Ray

Options: ReplyQuote


Subject
Written By
Posted
Problem storing dates!
June 18, 2021 08:08AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.