感谢您查看我的问题。我试图仅在该字段为空时更新我的数据库中的值(因此,如果有人尝试注册一个已准备就绪的位置并且将输出错误消息,则不会覆盖现有用户)。我在下面列出了我尝试过的 2 个最新脚本。如果 select 语句不存在,第一个脚本用于更新数据库,但如果在同一天和同一时间输入,则会覆盖用户。谢谢大家!
$sql = ("SELECT `player1` FROM `users` where id = '$id' and Times = '$time'");
$result = $conn->query($sql);
if ($result->fetch_assoc === NULL) {
$update_player = ("UPDATE users SET player1 = '$name' where id = '$id' AND Times = '$time'")
if($update_player){
echo "Date for $name inserted successfully!";
}
}
else {
echo 'That spot is all ready taken!';
}
//2nd script
$query=mysql_query("UPDATE users SET
player1 = isNULL (player1, $name)
where id = '$id' AND Times = '$time'" );
if($query){
echo "Data for $name inserted successfully!";
}
else {
echo 'That spot is all ready taken!';
}