我使用了prepare语句mysql,但其他语句不起作用

时间:2019-03-24 20:30:51

标签: mysql prepared-statement

我使用了prepare语句mysql来防止将空值或无效值插入到表中,我的问题是,即使没有将值插入表中,它也总是给我“成功创建新记录”,为什么else语句不这样做工作。

将数据插入MySQL表

//create a prepared statement 
$sql = "
    INSERT INTO subscribers (name, lastname, email, gender, comment, reg_date) 
    VALUES(?, ?, ?, ?, ?, CURRENT_TIME())";
$stmt = $conn->prepare($sql) ;
//bind parameters for markers
$stmt->bind_param("sssss", $_POST['name'], $_POST['lastname'], $_POST['email'], $_POST['gender'], $_POST['comment']);
//execute query
if ($stmt->execute()) {
     echo '<div class="mess">New record created successfully</div>';
} else {
    echo "not created" ;
}
$stmt->close();

0 个答案:

没有答案