对此可能有一个简单的答案,但我一生都无法让它发挥作用。
我正在使用 PHP 和 MySQL,并设置了类似的东西:
$studentname = mysql_real_escape_string($_POST['sname']);
$studentnumber = mysql_real_escape_string($_POST['snumber']);
$course = mysql_real_escape_string($_POST['courseselect']);
$bike3 = mysql_query("SELECT stoodnumber FROM bikes505 WHERE stoodname='" . $studentname . "'");
$bikestoods = mysql_fetch_array($bike3);
while($row = mysql_fetch_array($stoodlistq))
{
$stoodentname = $row['stoodname'];
$stoodentnumber = $row['stoodnumber'];
//$coursename = $row2['coursename'];
//$coursecode = $row2['coursecode'];
if($studentname == $stoodentname && $studentnumber == $stoodentnumber){
//$success = 1;
//$success = "yupp";
//echo "SUCCESS, WE CAN REGISTER YOOOU!";
echo "<br>";
//echo "INSERT INTO " . $course . "";
switch($course){
case "Biking Safely":
if($studentnumber = $bikestoods[0] or $bikestoods[1]){
echo "Sorry, this student has already registered";
} else if($bikecurrent < $bikemax){
mysql_query("INSERT INTO bikes505 VALUES ('" . $stoodentname . "','" . $stoodentnumber . "')");
echo "Yay, successfully registered " . $stoodentname . " - " . $stoodentnumber . " for " . $course;
echo "<br>";
} else{
echo "Sorry, class is full!";
}
break;
...等等。我遇到的唯一问题是,如果我有两个同名的学生,列表中的第二个学生会回显信息不正确。
例如,MySQL 表有 'stoodname' 和 'stoodnumber',如果 'Jimmy St.James','1010' 和 'Jimmy St.James','1090' 都是表中的记录,它只会让我注册课程中的 Jimmy 1010 而不是 Jimmy 1090。
我只是在验证我的方式吗?还是我错过了一些非常明显的东西?起初我认为这只是因为我只使用了数组中的第一项,$bikestoods[0]
所以我将其更改为$bikestoods[0] or $bikestoods[1]
它仍然无法正常工作。