下面是今天日期的計數記錄代碼,並且如果每天的值不超過兩個,則將其插入到數據庫中。現在的問題是我想插入數據庫if count for today低於2如果列計數值爲2,則將記錄插入到mysql表中
$user_ip = getenv('REMOTE_ADDR');
$geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$user_ip"));
$city = $geo["geoplugin_city"];
$region = $geo["geoplugin_regionName"];
$img = $_POST['img'];
$amount = 5;
$sql = "SELECT COUNT(*) FROM `daily_uploads` WHERE DATE_FORMAT(`date`, '%Y-%m-%d') = CURDATE()";
$result = $conn->query($sql);
if ($result->num_rows > 2) {
echo"already exist";
echo "Error: " . $sql . "<br>" . $conn->error;
} else {
$sql = "INSERT INTO `daily_uploads` (img, geoplugin_city, geoplugin_regionName, amount)
VALUES ('$img', '$city', '$region','$amount')";
// echo "success";
}
你不插入分貝的第二查詢,因爲你的天堂」執行它。 –