我想检查一个值是否已经在表中。我的表结构是这样的:
ApplicantId = INT
EventId = INT
StudentId = INT
不需要使用唯一的,因为这些表具有依赖关系。
以下是我迄今为止尝试过的:
include('../connectdb.php');
$ScholarPointId = $_GET["ScholarPointId"];
$Point = $_GET["Point"];
$ScholarId = $_GET["ScholarId"];
$EventId = $_GET["EventId"];
$verifysql = mysql_query("SELECT EventId FROM scholar_attended_events WHERE ScholarId ='$ScholarId' ");
#$resultVerify = mysql_fetch_assoc($verifysql);
$num_rows = mysql_num_rows($verifysql);
if( $num_rows > 0 )
{
$script = "<script>
alert('The user has already attended this event!');
</script>";
header('updatescholarpoints.php');
exit();
}
else{
$result = mysql_query("UPDATE scholar_points
SET scholar_points.Points =
scholar_points.Points + $Point
WHERE scholar_points.ScholarPointId = '$ScholarPointId' ") or die(mysql_error());
mysql_query("INSERT INTO scholar_attended_events (EventId , ScholarId) VALUES( '$EventId' , '$ScholarId' ) ")
or die(mysql_error());
}
?>
我想要的是检查 EventId 是否已经被 Student = StudentId 占用。如果是这样,那么系统将提示一个警告框。否则,更新并插入到相应的表中。我怎样才能做到这一点?看来我在这里错过了什么。如果你能帮忙,我真的很感激。