我做了类似的事情,但它不起作用。
我想检查该ID是否存在于数据库中,如果是,则插入数据,如果不存在,请重试。
我使用此代码进行检查,但似乎不起作用。
我输入正确或不正确的信息,它会转到accepted.html 页面,并且不会将数据插入我的时间表中。我希望它检查 ID 是否正确,将数据插入时间表中。
if ($player == null || $witness == null) {
echo "Do not use the same player and witness or maybe you forgot to add it...";
echo '<META HTTP-EQUIV="Refresh" Content="2; URL=index.php">';
} else {
$sql = "SELECT (`id`) FROM player WHERE id={$player} ";
$result = mysql_query($sql);
if ($result == true) {
$sql2 = "INSERT INTO `members` (`player`, `hours`, `minutes`, `witness`, `type`,`date`,`comments`) VALUES ('$player', '$hours', '$minutes', '$witness', '$type', '$date','$comments')";
$result2 = mysql_query($sql2);
if ($result2)
{
header('Location: accepted.html');
}
else {
echo mysql_error();
}
}else{
header('Location: contactAdmin.html');
}
}
最佳答案
$sql = "SELECT (`id`) FROM $tbl_name WHERE id=$$player ";
应该是
$sql = "SELECT `id` FROM $tbl_name WHERE id= $player ";
你有id=$$player
关于PHP MySQL 检查ID是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22441178/