我的课程作业部分是允许用户添加或删除课程。我从MySQL数据库中生成了一个学生从PHP中学习的类列表。我想让用户能够输入他们想要添加或删除的类。在他们键入要添加/删除的类之后,将生成更新的类列表。我不知道这是否可能以我要求的方式进行。
我的PHP代码是:
<?php
include("account.php");
//connect to MySQL database
session_start();
$dbc = mysqli_connect($hostname, $username, $password, $database) or die("Unable to connect to MySQL database");
echo "Connected to MySQL<br>";
$user = $_POST['name'];
$num = $_POST['number'];
$choice = $_POST['list'];
if(isset($_POST['Submit']))
{
if (empty ($user))
{
echo "you must enter your unique username <br />";
}
if (empty ($num))
{
echo "you must enter your ID <br />";
}
$query = "SELECT * FROM StudentDB WHERE StudentName = '". mysqli_real_escape_string($dbc,$user) ."' AND StudentID = '". mysqli_real_escape_string($dbc,$num) ."'" ;
$result = mysqli_query($dbc,$query);
if (mysqli_num_rows($result) == 1)
{
if ($choice == '1')
{
while($row = mysqli_fetch_array($result, MYSQLI_BOTH))
{
echo 'Student Name: ' . $row['StudentName'] . '| Student E-Mail: ' . $row['E-Mail'] .';'. '| Student ID: ' . $row['StudentID'] . '| Student Courses: ' . $row['Student Courses'] .'<br />';
}
}
if ($choice == '2')
{
while($row = mysqli_fetch_array($result, MYSQLI_BOTH))
{
echo 'Student Name: ' . $row['StudentName'] . '| Student E-Mail: ' . $row['E-Mail'] .';'. '| Student ID: ' . $row['StudentID'] . '| Student Courses: ' . $row['Student Courses'] .'| Student Transcript: ' . $row['Student Transcript'] .'<br />';
}
}
}
else
{
echo"unsuccessful login";
}
session_destroy();
}
else
{
echo "Empty";
}
?>
&#13;
这就是我看待它的样子(在我看来):
originial class list
add: type the class you want to add
drop: Type the class you want to drop
updated class list
我觉得无论如何都需要一个处理按钮来完成这项工作,但我不知道是否需要这样做。 任何帮助用户输入信息以更新班级列表的帮助都将不胜感激。
感谢。
很抱歉,如果这很麻烦或令人困惑,因为我的笔记本电脑即将死亡,而且我试图在此之前解决这个问题。