phpmysqldate

Can anyone tell me why I am getting all zeros in my date field


I'm fairly new to php, yes I know about the SQL injection attack, just trying to make this work. Everything posts to the mysql table properly except the date, I keep getting all zeros. Why? The field is set to datetime.

include('../htconfig/dbConfig.php'); 
$dbSuccess = false;
$dbConnected = mysql_connect($db['hostname'],$db['username'],$db['password']);

if ($dbConnected) {     
    $dbSelected = mysql_select_db($db['database'],$dbConnected);
    if ($dbSelected) {
        $dbSuccess = true;
    }   
}
$Sldate = date("m-d-Y");
$data_back = json_decode(file_get_contents('php://input'));


    $userName = $data_back->{"User"};
    $password = $data_back->{"Pword"};
    $SoldTo = $data_back->{"Soldto"};
    $SoldPrice = $data_back->{"SoldPrice"};
    $SoldEmail= $data_back->{"Email"};
    $VIN = $data_back->{"VIN"};



mysql_query("UPDATE tblinventory SET SOLD ='1',DATESLD = '$Sldate', DealerName='$SoldTo', SoldPrice = '$SoldPrice', DealerEmail = '$SoldEmail' WHERE VIN =$VIN");
echo ('SOLD');

///send email

?>

Solution

  • MySQL expects your date to be in YYYY-MM-DD format, not MM-DD-YYYY.

    $Sldate = date("Y-m-d");
    

    You could also remove the PHP portion of this code and do this directly in your SQL

    DATESLD = CURDATE()