tobig tobig - 6 months ago 21
PHP Question

MySQL+PHP Error: mysqli_stmt::execute() Incorrect datetime value: "

I'm new in PHP and MySQLi and trying to create an

editable paginated table
. But I'm getting stuck on date time update.

My add function works fine but when I'm trying to submit edit form I'm getting the following error:


mysqli_stmt::execute(): (22007/1292): Incorrect datetime value: "for column 'date'


Here is the part of errored lines code:

$id = $_POST['id'];
$name = htmlentities($_POST['name'], ENT_QUOTES);
$nummer = htmlentities($_POST['nummer'], ENT_QUOTES);
$stuck = htmlentities($_POST['stuck'], ENT_QUOTES);
$cdate = date(' Y-m-d H:i:s');

//check if empty
if($name == '' || $nummer == '' || $cdate = '' || $stuck == ''){
$error = 'ERROR: Please fill in all required fields!';
renderForm($name, $nummer, $cdate, $stuck, $error, $id);
}else{
// if everything is fine, update the record in the database
if($stmt = $mysqli->prepare("UPDATE ware SET name = ?, nummer = ?, date= ?, stuck = ? WHERE id=?")){
$stmt->bind_param("sssii",$name,$nummer, $cdate, $stuck, $id);
if(!$stmt->execute()) echo $stmt->error;
...


The full code can be found here: http://pastie.org/10824477

Answer

I found my mistake.

 if($name == '' || $nummer == '' || $cdate = '' || $stuck == ''){

should be

 if($name == '' || $nummer == '' || $cdate == '' || $stuck == ''){

Solved!

Comments