0
目前在我的代碼中,任何學生都可以留下任何數量的反饋。我想這樣做,所以每個學生只能在一個學期內給出兩個反饋。在SQL語句中添加PHP的時間限制?
我想我也必須在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>";
}
?>
插入之前,使用'COUNT(1)'和檢查? – hjpotter92
[**請不要在新代碼中使用'mysql_ *'函數**](http://bit.ly/phpmsql)。他們不再被維護[並且被正式棄用](http://j.mp/XqV7Lp)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 – Uby