目前在我的代码中,任何学生都可以留下任何数量的反馈。我想让每个学生在一个学期内只能给出两个反馈。
我想我也必须在 MySQL 中应用某种主键概念?
这是我的参考代码:
<?php
session_start();
if (isset($_SESSION['user_id'])) {
if (isset($_SESSION['user_id']) && isset($_POST['r1']) && isset($_POST['r2']) && isset($_POST['r3']) && isset($_POST['r4']) && isset($_POST['suggestion']) && isset($_POST['module'])) {
$module = $_POST['module'];
$user = $_SESSION['user_id'];
$r1 = $_POST['r1'];
$r2 = $_POST['r2'];
$r3 = $_POST['r3'];
$r4 = $_POST['r4'];
$suggestion = $_POST['suggestion'];
switch ($module) {
case 1:
$query_insert = "INSERT INTO `wp_feedback` VALUES ('" . $user . "','wp','" . $r1 . "','" . $r2 . "','" . $r3 . "','" . $r4 . "','" . $suggestion . "')";
if (isset($_POST['submit'])) {
if ($query_run = mysql_query($query_insert)) {
echo "<script type='text/javascript'>alert('Sucessfull');</script>";
header('Location: feedback.php');
}
else {
echo "not inserted";
}
}
break;
case 2:
$query_insert = "INSERT INTO `wp_feedback` VALUES ('" . $user . "','hssn2','" . $r1 . "','" . $r2 . "','" . $r3 . "','" . $r4 . "','" . $suggestion . "')";
if (isset($_POST['submit'])) {
if ($query_run = mysql_query($query_insert)) {
echo "<script type='text/javascript'>alert('Sucessfull');</script>";
header('Location: feedback.php');
}
else {
echo "not inserted";
}
}
break;
case 3:
$query_insert = "INSERT INTO `wp_feedback` VALUES ('" . $user . "','dwds','" . $r1 . "','" . $r2 . "','" . $r3 . "','" . $r4 . "','" . $suggestion . "')";
if (isset($_POST['submit'])) {
if ($query_run = mysql_query($query_insert)) {
echo "<script type='text/javascript'>alert('Sucessfull');</script>";
header('Location: feedback.php');
}
else {
echo "not inserted";
}
}
case 4:
case 3:
$query_insert = "INSERT INTO `wp_feedback` VALUES ('" . $user . "','ped','" . $r1 . "','" . $r2 . "','" . $r3 . "','" . $r4 . "','" . $suggestion . "')";
if (isset($_POST['submit'])) {
if ($query_run = mysql_query($query_insert)) {
echo "<script type='text/javascript'>alert('Sucessfull');</script>";
header('Location: feedback.php');
}
else {
echo "not inserted";
}
}
break;
default:
echo "select something";
break;
}
}
}
else {
echo "<script type='text/javascript'>alert('You must be login to View the contents');</script>";
}
?>