我在這裏遇到問題。首先,我在這裏做的是學生的學科註冊系統。我設置了一部分代碼來限制同一個學生一次又一次地註冊同一個主題。但令人遺憾的是,這給了我一個相反的效果。我的錯誤是,當一個學生註冊一個科目時,即使他們從未註冊過該科目,其他學生也不能註冊該特定科目。任何幫助將非常感激。主題註冊錯誤
<?php
if(!isset($_POST['submit'])){
exit('Unauthorized access!');
}
$name = $_POST['name'];
$studentid = $_POST['studentid'];
$program = $_POST['program'];
$fintake = $_POST['fintake'];
$courseid = $_POST['courseid'];
include("include/config.php");
//this could be the problem,i'm not sure
$check_query = mysqli_query($link, "SELECT r_id FROM course_registration WHERE r_cid='$courseid' limit 1");
if(mysqli_fetch_array($check_query))
{
echo 'Error:Course ID:',$courseid,' already exists. <a href="javascript:history.back(-1);">Return</a>';
exit;
}
$result = mysqli_query($link, "SELECT * FROM course_list WHERE c_cid = '$courseid'");
if(mysqli_fetch_array($result))
{
$sql = "INSERT INTO course_registration (r_name,r_sid,r_program,r_fintake,r_cid) VALUES('$name','$studentid','$program','$fintake','$courseid')";
if(mysqli_query($link,$sql))
{
exit('Success! Register course successfully. <a href="index.php">Homepage</a>');
}
else
{
echo 'Sorry! Add data failed:',mysqli_error($link),'<br />';
echo 'Click here <a href="javascript:history.back(-1);">Return</a> retry';
}
}
else
{
echo 'Sorry! Wrong course id.','<br />';
echo 'Click here <a href="javascript:history.back(-1);">Return</a> retry';
}
?>
數據庫:course_registration
r_id r_name r_sid r_program r_fintake r_cid
1 TAN KOON ENG 0187904 DIP-CS 01-2015 DTP-3033
2 TAN KOON ENG 0187904 DIP-CS 01-2015 DCS-22104
3 CRISTIANO RONALDO 0190007 DIP-GT 09-2016 DGP-2254
4 CRISTIANO RONALDO 0190007 DIP-GT 09-2016 DGA-1224
add where clause studentid = $ studenid。 – JYoThI