STR_TO_DATE

时间:2015-12-17 17:24:27

标签: php mysqli

  

您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   靠近' STR_TO_DATE(' 1988年2月4日''%米/%d /%Y&#39),

$sql  = "INSERT INTO customer_registration( ";
$sql .= "CUSTOMER_FNAME, CUSTOMER_LNAME, CUSTOMER_DOB, APARTMENT, ";
$sql .= "STREET, CITY, PROVINCE, POSTAL_CODE, EMAIL, PHONE, SIGN_IN_DATE ";
$sql .= ") VALUES (";
$sql .= " '{$fname}', {$lname}, STR_TO_DATE('$dob','%m/%d/%Y'), {$apt}, {$city}, {$province}, {$postalCode}, {$_email}, {$phone}, {NOW()}";
$sql .= ")";
$result= mysqli_query($connection, $sql);

什么似乎是错误?

2 个答案:

答案 0 :(得分:0)

为了使它能够工作,我所要做的就是添加引号并删除函数中的引号。

$sql  = "INSERT INTO customer_registration( ";
$sql .= "CUSTOMER_FNAME, CUSTOMER_LNAME, CUSTOMER_DOB, APARTMENT, ";
$sql .= "STREET, CITY, PROVINCE, POSTAL_CODE, EMAIL, PHONE, SIGN_IN_DATE ";
$sql .= ") VALUES (";
$sql .= " '{$fname}', '{$lname}', '{$dob}', '{$apt}', '{$street}', '{$city}', '{$province}', '{$postalCode}', '{$_email}', '{$phone}', NOW()";
$sql .= ")";

答案 1 :(得分:0)

1)在第一次约会时使用strtotime()。然后date('Y-m-d')将其转换回来。

2)在您的值中使用单引号'。与'{$lname}'

一样

3)从Now()

中删除单引号'
<?
$dob = strtotime($dob);
$dob = date('%m/%d/%Y',$dob);

$sql  = "INSERT INTO customer_registration( ";
$sql .= "CUSTOMER_FNAME, CUSTOMER_LNAME, CUSTOMER_DOB, APARTMENT, ";
$sql .= "STREET, CITY, PROVINCE, POSTAL_CODE, EMAIL, PHONE, SIGN_IN_DATE ";
$sql .= ") VALUES (";
$sql .= " '{$fname}', '{$lname}', '{$dob}', '{$apt}', '{$city}', '{$province}', '{$postalCode}', '{$_email}', '{$phone}', NOW()";
$sql .= ")";
$result= mysqli_query($connection, $sql);

?>