我的php中有以下内容。
$stmt = $conn->prepare("INSERT IGNORE INTO savesearch (user, searchedFor, sortOrder, buildURLString, aspectFilters, oneSignalId, totalEntries)
VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssssss", $user, $searchedFor, $sortOrder, $buildURLString, $aspectFilters, $oneSignalId, $totalEntries);
// set parameters and execute
$user = $_POST['user'];
$searchedFor = $_POST["searchedFor"];
$sortOrder = $_POST["sortOrder"];
$buildURLString = $_POST["buildURLString"];
$aspectFilters = $_POST["aspectFilters"];
$oneSignalId = $_POST["oneSignalId"];
$totalEntries = $_POST["totalEntries"];
if ($stmt->execute()) {
$output->success = true;
echo json_encode($output);
} else {
$error->error = mysqli_error($conn);
echo json_encode($error);
}
但是,忽略没有被拾取,它将继续添加条目。有没有别的好办法来解决这个问题?
我想看看用户和网址是否相同,不要添加,回音重复条目。
1条答案
按热度按时间5q4ezhmt1#
IGNORE
实际上主要是为了你想要的相反的东西。相反,您可以修改mysql表,如下所示:ALTER TABLE savesearch ADD UNIQUE KEY(user, buildURLString)
然后移除你的IGNORE
关键字