I do an INSERT into mySQL database like this:
$sDate=date("Y-m-d h:i:s");
INSERT INTO tbl_1 (datum) VALUES ('$sDate')
And it'll do the INSERT But then when I try to find out the unique ID by selecting the date like this:
SELECT id AS nyPost FROM tbl_1 WHERE datum ='$sDate'
It will return nothing, not even an error message. The datum format is datetime. Please whats wrong? CODE:
<?php
$sDate=date("Y-m-d h:i:s");
echo $sDate;
If ($strNy)
{
$_nyPrSQL="INSERT INTO begagnads (`anvId`, `tabort`, `datum`) VALUES ('8' , 'null', '$sDate')";
// echo $_nyPrSQL;
if (!mysqli_query($con,$_nyPrSQL))
{die('Error: ' . mysqli_error($con));}
else
{
echo "<br>1 record added";
}
$result = mysqli_query($con,"SELECT id FROM begagnads WHERE DATE(datum) ='$sDate' ");
while($row = mysqli_fetch_array($result)) {
echo $row['id'] . " " . $row['datum'];
$nyPost= $row['id'];
echo "<br>";
}
?>
MySql DATE()
function Extracts the date part of the date or datetime expression expr.
mysql> SELECT DATE('2003-12-31 01:02:03');
-> '2003-12-31'
If you want to find by DATE
only
SELECT id FROM begagnads WHERE DATE(datum) = DATE('$sDate')
And if you find with date and time then no need DATE()
function
SELECT id FROM begagnads WHERE datum = '$sDate'
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments