用户/管理员可以根据需要登录和注册学生。点击完成后我们需要提供 支付选项然后选择后我们需要为所有学生生成注册号码,所有学生必须在最后选择相同的支付选项。
我的问题是如何保存每个学生的表格值(包含近100个字段),直到他点击完成以及如何插入并生成所有这些学生的注册号
答案 0 :(得分:0)
您可以使用JQUERY来编辑html,根据需要添加更多其他字段。对于每个新学生,请在字段名称中增加ID号。在一个表单上提交所有信息,然后解析结果。
这篇文章讨论了如何使用jquery添加表单字段:Create new form fields with jQuery
答案 1 :(得分:0)
对于管理部分,您可以尝试:
session_start(['username']);
if (isset($_SESSION['username']))
{
$user = $_SESSION['username'];
$connect = mysql_connect("localhost","root","");
mysql_select_db("login");
$POST = mysql_query("SELECT * FROM users WHERE username='$user'");
while ($row = mysql_fetch_assoc($POST))
{
$admin = $row['account'];
}
if ($admin ==0)
die("You're not an admin <a href='member.php'>Main menu</a>");
}
else
die("You must be logged in <a href='index.php'>Back</a>");
?>
将帐户添加为您的一个数据库列表。
这是一个有用的教程:
https://www.youtube.com/watch?v=65gV8JOgWkQ&list=PL149E761860153CC8
用户表:
CREATE TABLE IF NOT EXISTS `users` (
`userid` int(11) NOT NULL AUTO_INCREMENT,
`firstname` varchar(25) NOT NULL,
`surname` varchar(25) NOT NULL,
`email` varchar(1024) NOT NULL,
`password` varchar(30) NOT NULL,
`username` varchar(25) NOT NULL,
`account` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=28 ;
报名表:
<?php
if (isset($_POST['forename'], $_POST['email'], $_POST['surname'], $_POST['password'], $_POST['repassword']))
{
$errors = array();
//form data
$forename = strip_tags($_POST['forename']);
$username = strtolower(strip_tags($_POST['username']));
$surname = strip_tags($_POST['surname']);
$password = strip_tags($_POST['password']);
$repassword = strip_tags($_POST['repassword']);
$email = $_POST['email'];
//connect to database
$connect = mysql_connect("localhost","root","");
mysql_select_db("login");
$namecheck = mysql_query("SELECT username FROM users WHERE username='$username'");
$count = mysql_num_rows($namecheck);
if (empty ($forename) || empty($email)){
$errors[] ='All fields are required';
}else{
if(strlen($forename) >25 || strlen($forename) <3) {
$errors[] = 'Your forename must be at least three letters long and a maximum of twenty letters';
}
if ($count!=0)
{
$errors[] = 'Username already taken';
}
if(strlen($surname) >25 || strlen($surname) <3) {
$errors[] = 'Your surname must be at least three letters long and a maximum of twenty letters';
}
if(strlen($username) >25 || strlen($username) <3) {
$errors[] = 'Your username must be at least three letters long and a maximum of twenty letters';
}
if(strlen($password) >25 || strlen($password) <3) {
$errors[] = 'Your password must be at least three letters long and a maximum of twenty letters';
}
if(($password) != ($repassword)) {
$errors[] = 'Your passwords do not match ';
}
if (filter_var($email, FILTER_VALIDATE_EMAIL) ===FALSE) {
$errors[] ='Please enter a valid email';
}
}
if(!empty($errors)){
foreach ($errors as $errors){
echo '<strong>',$errors ,'</strong><br />';
}
}else{
$password = md5($password);
$repassword = md5($repassword);
$queryreg = mysql_query ("
INSERT INTO users VALUES ('','$forename','$surname','$email','$password','$username','')
");
header("Refresh: 1; url=index.php");
die("you have registered <a href=index.php>Login</a>") ;
}
}
?>
<form action ="" method="POST">
<table>
<tr><td>Forename:</td><td><input type="text" name="forename" value='<?php if (isset($_POST['forename'])) echo $forename; ?>'/></td></tr>
<tr><td>Surname:</td><td><input type="text" name="surname" value='<?php if (isset($_POST['surname'])) echo $surname; ?>'/></td></tr>
<tr><td>Username:</td><td><input type='text' name='username' value='<?php if (isset($_POST['username'])) echo $username; ?>'/></td></tr>
<tr><td>Email:<td><input type ="text" name="email" value='<?php if (isset($_POST['email'])) echo $email; ?>'/><td></tr>
<tr><td>Password:</td><td><input type='password' name='password'/></td></tr>
<tr><td>Repeat password:</td><td><input type='password' name='repassword'/></td></tr>
<tr><td><input type="submit" value="Register"/></td></tr>
</table>
</form>
登录:
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
$errors = array();
if ($username&&$password)
{
$connect = mysql_connect("localhost","root","") or die ("Could not connect");
mysql_select_db ("login") or die ("Could not find database");
$query = mysql_query("SELECT * FROM users WHERE username ='$username'");
$numrows = mysql_num_rows($query);
if ($numrows !=0)
{
while ($row =mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
}
if ($username==$dbusername&&$password==$dbpassword)
{
echo header( 'Location: member.php' ) ;
$_SESSION['username']=$dbusername;
$_SESSION['userid']=$userid;
}
else
//echo "Inncorrect password";
echo "
<script type=\"text/javascript\">
var text = document.createTextNode('Mmm ... something');
document.getElementById('myBtn').addEventListener('click', textchange1);
</script>
";
}
}
else
die("That user dosen't exist");
}
else
die("Please enter a username and a password");
if(isset($_POST['btn'])){
?>
用户名:
密码:
寄存器