我第一次尝试使用准备好的语句以避免 SQL 注入(inject),但当我尝试插入或更新数据库时,我似乎遇到了问题,我使用这些行来执行我想要的操作:
插入:
$stmt = $con->prepare("INSERT INTO my_array (image1,image2,image3,image4, info, type, lat, lng, date_created, status, created_by, closed_by, date_finished) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") ;
$stmt->bind_param('bbbbssddsssss', $image1, $image2, $image3, $image4, $info, $type, $lat, $long, $date, $opened, $user, $closed_by, $closed_by, $date_finished);
$stmt->execute();
$result = $stmt->get_result();
更新:
$stmt = $con->prepare("UPDATE users SET fullname = IF(LENGTH(?) = 0, fullname, ?), email = IF(LENGTH(?) = 0, email, ?), phone_num = IF(LENGTH(?) = 0, phone_num, ?) , address = IF(LENGTH(?) = 0, address, ?) WHERE username = '$user'") ;
$stmt->bind_param('ssssiiss',$fullname, $fullname, $email, $email, $phone_number , $phone_number, $address, $address);
$stmt->execute();
$result = $stmt->get_result();
在这两个结果中我都得到了“假”结果。
最佳答案
在第一个中,您有 $lined_by
重复项。
在第二个中,准备好的语句中有 $user
。那一定是一个参数。
关于php - 插入时准备好的语句错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25293327/