-----------------------------------------------------------------------------------------
# yum -y install httpd
# rpm -qa | grep httpd
httpd-tools-2.4.6-90.el7.centos.x86_64
httpd-2.4.6-90.el7.centos.x86_64
# systemctl start httpd.service
# systemctl enable httpd.service
# systemctl status httpd.service
# firewall-cmd --add-service=http --permanent
# firewall-cmd --reload
# firewall-cmd --list-all
http://192.168.1.4/
-----------------------------------------------------------------------------------------
# yum -y install php php-mysql php-devel php-mbstring
# rpm -qa | grep php
php-cli-5.4.16-46.el7.x86_64
php-devel-5.4.16-46.el7.x86_64
php-5.4.16-46.el7.x86_64
php-common-5.4.16-46.el7.x86_64
php-pdo-5.4.16-46.el7.x86_64
php-mysql-5.4.16-46.el7.x86_64
php-mbstring-5.4.16-46.el7.x86_64
# vi /etc/php.ini
...
display_errors = On
...
# systemctl restart httpd.service
-----------------------------------------------------------------------------------------
yum -y install mariadb-server
# rpm -qa | grep mariadb
mariadb-libs-5.5.64-1.el7.x86_64
mariadb-5.5.64-1.el7.x86_64
mariadb-server-5.5.64-1.el7.x86_64
# systemctl start mariadb.service
# systemctl enable mariadb.service
# systemctl status mariadb.service
# mysqladmin -u root password db123456
# mysql -u root -p
Enter password:
MariaDB [(none)]> create database kkdb character set='utf8' collate='utf8_unicode_ci';
MariaDB [(none)]> use kkdb;
MariaDB [kkdb]> create table tblstu (sid int primary key auto_increment, gra varchar(1), cla varchar(2), sno varchar(2), na varchar(10), pwd varchar(10));
MariaDB [kkdb]> show create table tblstu \G;
*************************** 1. row ***************************
Table: tblstu
Create Table: CREATE TABLE `tblstu` (
`sid` int(11) NOT NULL AUTO_INCREMENT,
`gra` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL,
`cla` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL,
`sno` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL,
`na` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`pwd` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`sid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
------------------------------------------------------------ 匯出資料
MariaDB [kkdb]> SELECT @n:=@n+1 AS 題號, ans AS 答案, qus AS 題目, concat('(A)',opt1) AS 選項1, concat('(B)',opt2) AS 選項2, concat('(C)',opt3) AS 選項3, concat('(D)',opt4) AS 選項4 INTO OUTFILE 'qus2.txt' FROM tblexam,(SELECT @n:=0) AS tmp;
MariaDB [kkdb]> SELECT @n:=@n+1 AS 題號, ans AS 答案, qus AS 題目, concat('(A)',opt1) AS 選項1, concat('(B)',opt2) AS 選項2, concat('(C)',opt3) AS 選項3, concat('(D)',opt4) AS 選項4 INTO OUTFILE 'qus2.csv' FROM tblexam,(SELECT @n:=0) AS tmp;
# ls /var/lib/mysql/kkdb
db.opt qus2.csv qus2.txt tblch.frm tblexam.frm tblsr.frm tblstu.frm
# cp /var/lib/mysql/kkdb/qus2.csv /home/s301/40/
//csv會亂碼,所以用txt再以word開啟,再修改版面
------------------------------------------------------ addqus.php
<?php
if (isset($_POST['qus']))
{
require_once("connMysql.php");
$sql="INSERT INTO tblexam (chid, qus, opt1, opt2, opt3, opt4, ans) VALUES ('".$_POST['chpr']."','".$_POST['qus']."','".$_POST['opt1']."','".$_POST['opt2']."','".$_POST['opt3']."','".$_POST['opt4']."','".$_POST['ans']."')";
$rslt=mysqli_query($conn,$sql);
header("Location:addqus.php");
}
else
{
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
require_once("connMysql.php");
$sql="SELECT chid,chpr FROM tblch ORDER BY chpr";
$rslt=mysqli_query($conn,$sql);
?>
<div id='container'>
<header>
<h1>新增測驗題目</h1>
<nav>
<ul>
<li><a href='lspwd.php'>各班級密碼</a></li>
<li><a href='lssr.php'>各班級測驗記錄</a></li>
<li><a href='addqus.php'>新增測驗題目</a></li>
<li><a href='chat.php'>吾聊天地</a></li>
<li><a href='message.php'>留言板頁</a></li>
</ul>
</nav>
</header>
<form action="addqus.php" method="post">
<table>
<tr>
<td>章節名</td>
<td>
<select name="chpr" required>
<option value="">請選擇</option>
<?php
while ($row=mysqli_fetch_assoc($rslt) )
echo("<OPTION VALUE=".$row['chid'].">".$row['chpr']."</OPTION>");
?>
</select>
</td>
</tr>
<tr>
<td>題目</td>
<td>
<input name="qus" type="text" maxlength="100" size="100" required>
</td>
</tr>
<tr>
<td>選項1</td>
<td>
<input name="opt1" type="text" maxlength="50" size="50" required>
</td>
</tr>
<tr>
<td>選項2</td>
<td>
<input name="opt2" type="text" maxlength="50" size="50" required>
</td>
</tr>
<tr>
<td>選項3</td>
<td>
<input name="opt3" type="text" maxlength="50" size="50" required>
</td>
</tr>
<tr>
<td>選項4</td>
<td>
<input name="opt4" type="text" maxlength="50" size="50" required>
</td>
</tr>
<tr>
<td>答案</td>
<td>
<select name="ans" required>
<option value="">請選擇</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" value="新增題目" name="ok">
</td>
</tr>
</table>
</form>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</div>
<p>
<h1>以下列出所有已收錄題目:</h1>
<?php
$sql="SELECT * FROM tblexam ORDER BY chid, qid";
$rslt=mysqli_query($conn,$sql);
while ($row=mysqli_fetch_assoc($rslt))
{
echo $row['qid'],"-->", $row['chid'];
echo "</br>";
echo $row['qus'], $row['opt1'], $row['opt2'], $row['opt3'], $row['opt4'];
echo "</br>";
echo $row['ans'];
echo "</br>";
echo "<p>";
};
?>
</body>
</html>
<?php
}
?>
------------------------------------------------------------ lspwd.php
<?php
if (isset($_POST['cla']))
{
require_once("connMysql.php");
$sql="SELECT sno,na,pwd FROM tblstu WHERE gra='".$_POST['gra']."' AND cla='".$_POST['cla']."'";
$rslt=mysqli_query($conn,$sql);
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id='container'>
<header>
<h1>各班級密碼</h1>
<nav>
<ul>
<li><a href='lspwd.php'>各班級密碼</a></li>
<li><a href='lssr.php'>各班級測驗記錄</a></li>
<li><a href='addqus.php'>新增測驗題目</a></li>
<li><a href='chat.php'>吾聊天地</a></li>
<li><a href='message.php'>留言板頁</a></li>
</ul>
</nav>
</header>
<section>
<table>
<tr>
<th>座號</th>
<th>名字</th>
<th>密碼</th>
</tr>
<?php
while ($row=mysqli_fetch_assoc($rslt))
{
?>
<tr>
<td><?php echo $row['sno'] ?></td>
<td><?php echo $row['na'] ?></td>
<td><?php echo $row['pwd'] ?></td>
</tr>
<?php
}
?>
</table>
</section>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</div>
</body>
</html>
<?php
}
else
{
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id='container'>
<header>
<h1>各班級密碼</h1>
<nav>
<ul>
<li><a href='lspwd.php'>各班級密碼</a></li>
<li><a href='lssr.php'>各班級測驗記錄</a></li>
<li><a href='addqus.php'>新增測驗題目</a></li>
<li><a href='chat.php'>吾聊天地</a></li>
<li><a href='message.php'>留言板頁</a></li>
</ul>
</nav>
</header>
<section>
<form action="lspwd.php" method="post">
年級:
<select name="gra" required>
<option value="">請選擇</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
班級:
<select name="cla" required>
<option value="">請選擇</option>
<?php
for ($i=1;$i<=19;$i++)
{
?>
<option value="<?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?>"><?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?></option>
<?php
}
?>
</select>
<p>
<input type="submit" value="查詢資料" name="ok">
</p>
</form>
</section>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</div>
</body>
</html>
<?php
}
?>
---------------------------------------------------------------- lssr.php
<?php
if (isset($_POST['cla']))
{
require_once("connMysql.php");
$sql="SELECT tblstu.sno,tblch.chpr,tblsr.scr,tblsr.dte FROM tblsr LEFT JOIN tblstu ON tblsr.sid=tblstu.sid LEFT JOIN tblch ON tblsr.chid=tblch.chid WHERE tblstu.gra='".$_POST['gra']."' AND tblstu.cla='".$_POST['cla']."'";
$rslt=mysqli_query($conn,$sql);
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id='container'>
<header>
<h1>各班級測驗記錄</h1>
<nav>
<ul>
<li><a href='lspwd.php'>各班級密碼</a></li>
<li><a href='lssr.php'>各班級測驗記錄</a></li>
<li><a href='addqus.php'>新增測驗題目</a></li>
<li><a href='chat.php'>吾聊天地</a></li>
<li><a href='message.php'>留言板頁</a></li>
</ul>
</nav>
</header>
<section>
<table>
<tr>
<th>座號</th>
<th>章節</th>
<th>分數</th>
<th>日期</th>
</tr>
<?php
while ($row=mysqli_fetch_assoc($rslt))
{
?>
<tr>
<td><?php echo $row['sno'] ?></td>
<td><?php echo $row['chpr'] ?></td>
<td><?php echo $row['scr'] ?></td>
<td><?php echo $row['dte'] ?></td>
</tr>
<?php
}
?>
</table>
</section>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</div>
</body>
</html>
<?php
}
else
{
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id='container'>
<header>
<h1>各班級測驗記錄</h1>
<nav>
<ul>
<li><a href='lspwd.php'>各班級密碼</a></li>
<li><a href='lssr.php'>各班級測驗記錄</a></li>
<li><a href='addqus.php'>新增測驗題目</a></li>
<li><a href='chat.php'>吾聊天地</a></li>
<li><a href='message.php'>留言板頁</a></li>
</ul>
</nav>
</header>
<section>
<form action="lssr.php" method="post">
年級:
<select name="gra" required>
<option value="">請選擇</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
班級:
<select name="cla" required>
<option value="">請選擇</option>
<?php
for ($i=1;$i<=19;$i++)
{
?>
<option value="<?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?>"><?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?></option>
<?php
}
?>
</select>
<P>
<input type="submit" value="查詢資料" name="ok">
</P>
</form>
</section>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</div>
</body>
</html>
<?php
}
?>
--------------------------------------------------------------------- score.php
<?php
session_start();
require_once("connMysql.php");
$sql="SELECT tblsr.scr, tblch.chpr FROM tblsr INNER JOIN tblch ON tblsr.chid=tblch.chid WHERE tblsr.sid=".$_SESSION['sid'];
$rslt=mysqli_query($conn,$sql);
$cnt=mysqli_num_rows($rslt);
if ($cnt>0)
{
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id='container'>
<header>
<h1>測驗記錄</h1>
<nav>
<ul>
<li><a href='exam.php'>線上測驗</a></li>
<li><a href='score.php'>測驗記錄</a></li>
<li><a href='chat.php'>吾聊天地</a></li>
<li><a href='message.php'>留言板頁</a></li>
</ul>
</nav>
</header>
<section>
<table>
<tr>
<th>章節</th>
<th>分數</th>
</tr>
<?php
while ($row=mysqli_fetch_assoc($rslt))
{
?>
<tr>
<td><?php echo $row['chpr'] ?></td>
<td><?php echo $row['scr'] ?></td>
</tr>
<?php
}
?>
</table>
</section>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</div>
</body>
</html>
<?php
}
else
{
?>
<script language="javascript">;
alert("目前尚無測驗資料...");
window.location.href="menu.html"
</script>;
<?php
}
?>
--------------------------------------------------------------------- add.php
<?php
if (isset($_POST['pwd']))
{
require_once("connMysql.php");
$sql="SELECT * FROM tblstu WHERE gra='".$_POST['gra']."' AND cla='".$_POST['cla']."' AND sno='".$_POST['sno']."' AND na='".$_POST['na']."'";
$rslt=mysqli_query($conn,$sql);
$cnt=mysqli_num_rows($rslt);
if ($cnt>0)
{
?>
<script language="javascript">;
alert("註冊資料已經重複!");
history.go(-1)
</script>;
<?php
}
else
{
$sql="INSERT INTO tblstu (gra, cla, sno, na, pwd) VALUES ('".$_POST['gra']."','".$_POST['cla']."','".$_POST['sno']."','".$_POST['na']."','".$_POST['pwd']."')";
$rslt=mysqli_query($conn,$sql);
?>
<script language="javascript">;
alert("新增註冊資料完成!請登入系統...");
window.location.href="index.php"
</script>;
<?php
}
}
else
{
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id='container'>
<header>
<h1>註冊資料</h1>
<nav>
<ul>
<li><a href='exam.php'>線上測驗</a></li>
<li><a href='score.php'>測驗記錄</a></li>
<li><a href='chat.php'>吾聊天地</a></li>
<li><a href='message.php'>留言板頁</a></li>
</ul>
</nav>
</header>
<section>
<form action="add.php" method="post">
<table>
<tr>
<td>年級</td>
<td>
<select name="gra" required>
<option value="">請選擇</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</td>
<td>班級</td>
<td>
<select name="cla" required>
<option value="">請選擇</option>
<?php
for ($i=1;$i<=19;$i++)
{
?>
<option value="<?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?>"><?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?></option>
<?php
}
?>
</select>
</td>
<td>座號</td>
<td>
<select name="sno" required>
<option value="">請選擇</option>
<?php
for ($i=1;$i<=29;$i++)
{
?>
<option value="<?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?>"><?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>姓名</td>
<td>
<input name="na" type="text" required>
</td>
<td>密碼</td>
<td>
<input name="pwd" type="password" maxlength="10" placeholder="最長10字元" required>
</td>
</tr>
<tr>
<td>
<input type="submit" value="註冊資料" name="ok">
</td>
</tr>
</table>
</form>
</section>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</div>
</body>
</html>
<?php
}
?>
--------------------------------------------------------------------- menu.html
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id='container'>
<header>
<h1>功能選單</h1>
<nav>
<ul>
<li><a href='exam.php'>線上測驗</a></li>
<li><a href='score.php'>測驗記錄</a></li>
<li><a href='chat.php'>吾聊天地</a></li>
<li><a href='message.php'>留言板頁</a></li>
</ul>
</nav>
</header>
<section>
</section>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</div>
</body>
</html>
--------------------------------------------------------------------- index.php V3.0
<?php
if (isset($_POST['pwd']))
if ($_POST['pwd']=="!QAZ@WSX")
{
header("Location:menu0.html");
}
else
{
session_start();
require_once("connMysql.php");
$sql="SELECT * FROM tblstu WHERE gra='".$_POST['gra']."' AND cla='".$_POST['cla']."' AND sno='".$_POST['sno']."' AND pwd='".$_POST['pwd']."'";
$rslt=mysqli_query($conn,$sql);
$row=mysqli_fetch_assoc($rslt);
if (is_null($row['sid']))
{
?>
<script language="javascript">;
alert("沒有註冊資料!請先註冊...");
window.location.href="add.php"
</script>;
<?php
}
else
{
$_SESSION['sid']=$row['sid'];
$_SESSION['gra']=$row['gra'];
$_SESSION['cla']=$row['cla'];
$_SESSION['na']=$row['na'];
header("Location:menu.html");
}
}
else
{
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id='container'>
<header>
<h1>同學登入</h1>
<nav>
<ul>
<li><a href='exam.php'>線上測驗</a></li>
<li><a href='score.php'>測驗記錄</a></li>
<li><a href='chat.php'>吾聊天地</a></li>
<li><a href='message.php'>留言板頁</a></li>
</ul>
</nav>
</header>
<section>
</section>
<form action="index.php" method="post">
<table>
<tr>
<td>年級</td>
<td>
<select name="gra" required>
<option value="">請選擇</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</td>
<td>
</td>
<td>
</td>
<td>班級</td>
<td>
<select name="cla" required>
<option value="">請選擇</option>
<?php
for ($i=1;$i<=19;$i++)
{
?>
<option value="<?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?>"><?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?></option>
<?php
}
?>
</select>
</td>
<td></td>
<td></td>
<td>座號</td>
<td>
<select name="sno" required>
<option value="">請選擇</option>
<?php
for ($i=1;$i<=29;$i++)
{
?>
<option value="<?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?>"><?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?></option>
<?php
}
?>
</select>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
<td>密碼</td>
<td colspan="9">
<input name="pwd" type="password" maxlength="10" required>
</td>
</tr>
<tr>
</tr>
<tr>
<td colspan="10">
<input type="submit" value="登入網站" name="ok">
</td>
</tr>
<tr>
</tr>
<tr>
<td colspan="10">
<a href="add.php">新同學註冊資料</a>
</td>
</tr>
</table>
</form>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</div>
</body>
</html>
<?php
}
?>
~
--------------------------------------------------------------------- exam.php V3.0
<?php
session_start();
if (isset($_POST['chpr']))
{
$_SESSION['chid']=$_POST['chpr'];
require_once("connMysql.php");
$sql="SELECT * FROM tblexam where chid='".$_POST['chpr']."' ORDER BY RAND() LIMIT 10";
$rslt=mysqli_query($conn,$sql);
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id='container'>
<header>
<h1>線上測驗</h1>
<nav>
<ul>
<li><a href='exam.php'>線上測驗</a></li>
<li><a href='score.php'>測驗記錄</a></li>
<li><a href='chat.php'>吾聊天地</a></li>
<li><a href='message.php'>留言板頁</a></li>
</ul>
</nav>
</header>
<form action="check.php" method="post">
<?php
$i=1;
while ($row=mysqli_fetch_assoc($rslt))
{
?>
<select name="sel<?php echo $i ?>" required>
<option >請選擇</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
</select>
<font size="4" color="Brown"><?php echo $i ?>.</font>
<font size="4" color="DarkBlue"><?php echo $row['qus'] ?></font></br>
(A)<?php echo $row['opt1'] ?>
(B)<?php echo $row['opt2'] ?>
(C)<?php echo $row['opt3'] ?>
(D)<?php echo $row['opt4'] ?>
<input type="hidden" name=q<?php echo $i ?> value="<?php echo ord($row['ans'])+2019 ?>">
<p>
<?php
$i++;
}
?>
<input type="submit" value="我答完了" name="ok">
</form>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</div>
</body>
</html>
<?php
}
else
{
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id='container'>
<?php
require_once("connMysql.php");
$sql="SELECT chid,chpr FROM tblch WHERE gra='".$_SESSION['gra']."' ORDER BY chpr";
$rslt=mysqli_query($conn,$sql);
?>
<header>
<h1>選擇測驗範圍</h1>
<nav>
<ul>
<li><a href='exam.php'>線上測驗</a></li>
<li><a href='score.php'>測驗記錄</a></li>
<li><a href='chat.php'>吾聊天地</a></li>
<li><a href='message.php'>留言板頁</a></li>
</ul>
</nav>
</header>
<form action="exam.php" method="post">
<table>
<tr>
<td>章節名</td>
<td>
<select name="chpr" required>
<option value="">請選擇</option>
<?php
while ($row=mysqli_fetch_assoc($rslt) )
echo("<OPTION VALUE=".$row['chid'].">".$row['chpr']."</OPTION>");
?>
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" value="確定範圍" name="ok">
</td>
</tr>
</table>
</form>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</div>
</body>
</html>
<?php
}
?>
--------------------------------------------------------------------- check.php V3.0
<?php
session_start();
$scr=0;
for ($i=1;$i<=10;$i++)
{
if ($_POST["sel$i"]==chr($_POST["q$i"]-2019))
{
$scr++;
}
}
require_once("connMysql.php");
date_default_timezone_set('Asia/Taipei');
$dte=date("Y/m/d H:i:s");
$sql="INSERT INTO tblsr (sid, chid, scr, dte) VALUES (".$_SESSION['sid'].",".$_SESSION['chid'].",".$scr.",'".$dte."')";
$rslt=mysqli_query($conn,$sql);
?>
<script language="javascript">;
alert("本次測驗共答對<?php echo $scr ?>題!!");
window.location.href="menu.html"
</script>;
--------------------------------------------------------------------- add.php V2
<?php
if (isset($_POST['pwd']))
{
require_once("connMysql.php");
$sql="SELECT * FROM tblstu WHERE gra='".$_POST['gra']."' AND cla='".$_POST['cla']."' AND sno='".$_POST['sno']."' AND na='".$_POST['na']."'";
$rslt=mysqli_query($conn,$sql);
$cnt=mysqli_num_rows($rslt);
if ($cnt>0)
{
?>
<script language="javascript">;
alert("註冊資料已經重複!");
history.go(-1)
</script>;
<?php
}
else
{
$sql="INSERT INTO tblstu (gra, cla, sno, na, pwd) VALUES ('".$_POST['gra']."','".$_POST['cla']."','".$_POST['sno']."','".$_POST['na']."','".$_POST['pwd']."')";
$rslt=mysqli_query($conn,$sql);
?>
<script language="javascript">;
alert("新增註冊資料完成!請登入系統...");
window.location.href="index.php"
</script>;
<?php
}
}
else
{
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id='container'>
<header>
<h1>註冊資料</h1>
<nav>
<ul>
<li><a href='exam.php'>線上測驗</a></li>
<li><a href='#'>修改密碼</a></li>
<li><a href='#'>吾聊天地</a></li>
</ul>
</nav>
</header>
<section>
<form action="add.php" method="post">
<table>
<tr>
<td>年級</td>
<td>
<select name="gra" required>
<option value="">請選擇</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</td>
<td>班級</td>
<td>
<select name="cla" required>
<option value="">請選擇</option>
<?php
for ($i=1;$i<=19;$i++)
{
?>
<option value="<?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?>"><?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?></option>
<?php
}
?>
</select>
</td>
<td>座號</td>
<td>
<select name="sno" required>
<option value="">請選擇</option>
<?php
for ($i=1;$i<=29;$i++)
{
?>
<option value="<?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?>"><?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>姓名</td>
<td>
<input name="na" type="text" required>
</td>
<td>密碼</td>
<td>
<input name="pwd" type="password" maxlength="10" placeholder="最長10字元" required>
</td>
</tr>
<tr>
<td>
<input type="submit" value="註冊資料" name="ok">
</td>
</tr>
</table>
</form>
</section>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</div>
</body>
</html>
<?php
}
?>
--------------------------------------------------------------------- menu.html
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id='container'>
<header>
<h1>功能選單</h1>
<nav>
<ul>
<li><a href='exam.php'>線上測驗</a></li>
<li><a href='#'>修改密碼</a></li>
<li><a href='#'>吾聊天地</a></li>
</ul>
</nav>
</header>
<section>
</section>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</div>
</body>
</html>
--------------------------------------------------------------------- menu0.html
--------------------------------------------------------------------- exam.php
<?php
session_start();
if (isset($_POST['chpr']))
{
$_SESSION['chid']=$_POST['chpr'];
require_once("connMysql.php");
$sql="SELECT * FROM tblexam where chid='".$_POST['chpr']."' ORDER BY RAND() LIMIT 10";
$rslt=mysqli_query($conn,$sql);
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id='container'>
<header>
<h1>線上測驗</h1>
<nav>
<ul>
<li><a href='exam.php'>線上測驗</a></li>
<li><a href='#'>修改密碼</a></li>
<li><a href='#'>吾聊天地</a></li>
</ul>
</nav>
</header>
<form action="check.php" method="post">
<?php
$i=1;
while ($row=mysqli_fetch_assoc($rslt))
{
?>
<input type="hidden" name=q<?php echo $i ?> value="<?php echo $row['ans'] ?>">
<font size="4" color="Brown"><?php echo $i ?>.</font>
<font size="4" color="DarkBlue"><?php echo $row['qus'] ?></font></br>
<input type="radio" name="rdo<?php echo $i ?>" value="A"><?php echo $row['opt1'] ?>
<input type="radio" name="rdo<?php echo $i ?>" value="B"><?php echo $row['opt2'] ?>
<input type="radio" name="rdo<?php echo $i ?>" value="C"><?php echo $row['opt3'] ?>
<input type="radio" name="rdo<?php echo $i ?>" value="D"><?php echo $row['opt4'] ?>
<p>
<?php
$i++;
}
?>
<input type="submit" value="我答完了" name="ok">
</form>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</div>
</body>
</html>
<?php
}
else
{
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id='container'>
<?php
require_once("connMysql.php");
$sql="SELECT chid,chpr FROM tblch WHERE gra='".$_SESSION['gra']."' ORDER BY chpr";
$rslt=mysqli_query($conn,$sql);
?>
<header>
<h1>選擇測驗範圍</h1>
<nav>
<ul>
<li><a href='exam.php'>線上測驗</a></li>
<li><a href='#'>修改密碼</a></li>
<li><a href='#'>吾聊天地</a></li>
</ul>
</nav>
</header>
<form action="exam.php" method="post">
<table>
<tr>
<td>章節名</td>
<td>
<select name="chpr" required>
<option value="">請選擇</option>
<?php
while ($row=mysqli_fetch_assoc($rslt) )
echo("<OPTION VALUE=".$row['chid'].">".$row['chpr']."</OPTION>");
?>
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" value="確定範圍" name="ok">
</td>
</tr>
</table>
</form>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</div>
</body>
</html>
<?php
}
?>
--------------------------------------------------------------------- check.php
<?php
session_start();
$scr=0;
for ($i=1;$i<=10;$i++)
{
if ($_POST["rdo$i"]==$_POST["q$i"])
{
$scr++;
}
}
require_once("connMysql.php");
$sql="INSERT INTO tblsr (sid, chid, scr) VALUES (".$_SESSION['sid'].",".$_SESSION['chid'].",".$scr.")";
$rslt=mysqli_query($conn,$sql);
?>
<script language="javascript">;
alert("本次測驗共答對<?php echo $scr ?>題!!");
window.location.href="menu.html"
</script>;
---------------------------------------------------------------------- index.php V2
<?php
if (isset($_POST['pwd']))
if ($_POST['pwd']=="!QAZ@WSX")
{
header("Location:menu0.html");
}
else
{
session_start();
require_once("connMysql.php");
$sql="SELECT * FROM tblstu WHERE gra='".$_POST['gra']."' AND cla='".$_POST['cla']."' AND sno='".$_POST['sno']."' AND pwd='".$_POST['pwd']."'";
$rslt=mysqli_query($conn,$sql);
$row=mysqli_fetch_assoc($rslt);
if (is_null($row['sid']))
{
?>
<script language="javascript">;
alert("沒有註冊資料!請先註冊...");
window.location.href="add.php"
</script>;
<?php
}
else
{
$_SESSION['sid']=$row['sid'];
$_SESSION['gra']=$row['gra'];
header("Location:menu.html");
}
}
else
{
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id='container'>
<header>
<h1>同學登入</h1>
<nav>
<ul>
<li><a href='exam.php'>線上測驗</a></li>
<li><a href='#'>修改密碼</a></li>
<li><a href='#'>吾聊天地</a></li>
</ul>
</nav>
</header>
<section>
</section>
<form action="index.php" method="post">
<table>
<tr>
<td>年級</td>
<td>
<select name="gra" required>
<option value="">請選擇</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</td>
<td>班級</td>
<td>
<select name="cla" required>
<option value="">請選擇</option>
<?php
for ($i=1;$i<=19;$i++)
{
?>
<option value="<?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?>"><?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?></option>
<?php
}
?>
</select>
</td>
<td>座號</td>
<td>
<select name="sno" required>
<option value="">請選擇</option>
<?php
for ($i=1;$i<=29;$i++)
{
?>
<option value="<?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?>"><?php echo str_pad($i,2,'0',STR_PAD_LEFT) ?></option>
<?php
}
?>
</select>
</tr>
<tr>
<td>密碼</td>
<td>
<input name="pwd" type="password" maxlength="10" required>
</td>
</tr>
<tr>
<td>
<input type="submit" value="登入網站" name="ok">
</td>
</tr>
</table>
</form>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</div>
</body>
</html>
<?php
}
?>
---------------------------------------------------------------------- add.html
# vi /var/www/html/add.html
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<header>
<h1>註冊會員資料</h1>
<nav>修改密碼 線上測驗 療聊園地
</nav>
</header>
<section>
</section>
<article>
<form action="add.php" method="post">
<table>
<tr>
<td>年級</td>
<td>
<select name="gra" required>
<option value="">請選擇</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</td>
<td>班級</td>
<td>
<select name="cla" required>
<option value="">請選擇</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
</select>
</td>
<td>座號</td>
<td>
<select name="sno" required>
<option value="">請選擇</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
</select>
</td>
</tr>
<tr>
<td>姓名</td>
<td>
<input name="na" type="text" required>
</td>
<td>密碼</td>
<td>
<input name="pwd" type="password" maxlength="10" placeholder="最長10字元" required>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<input type="submit" value="註冊資料" name="ok">
</td>
</tr>
</table>
</form>
</article>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</body>
</html>
------------------------------------------------------------------------------- add.php
# vi /var/www/html/add.php
<?php
if (isset($_POST['pwd'])){
$conn=mysqli_connect("localhost","root","db123456","kkdb");
if (mysqli_connect_errno($conn))
die("無法連線!");
mysqli_set_charset($conn,"utf8");
$sql="SELECT * FROM tblstu WHERE gra='".$_POST['gra']."' AND cla='".$_POST['cla']."' AND sno='".$_POST['sno']."' AND na='".$_POST['na']."'";
$rslt=mysqli_query($conn,$sql);
$cnt=mysqli_num_rows($rslt);
if ($cnt>0){
?>
<script language="javascript">;
alert("註冊資料已經重複!");
history.go(-1)
</script>;
<?php
}
else{
$sql="INSERT INTO tblstu (gra, cla, sno, na, pwd) VALUES ('".$_POST['gra']."','".$_POST['cla']."','".$_POST['sno']."','".$_POST['na']."','".$_POST['pwd']."')";
$rslt=mysqli_query($conn,$sql);
?>
<script language="javascript">;
alert("新增註冊資料完成!請登入系統...");
window.location.href="index.html"
</script>;
<?php
}
}
?>
----------------------------------------------------------------------------------------- index.html
# vi /var/www/html/index.html
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<header>
<h1>同學登入</h1>
<nav>修改密碼 線上測驗 療聊園地
</nav>
</header>
<section>
</section>
<article>
<form action="login.php" method="post">
<table>
<tr>
<td>年級</td>
<td>
<select name="gra" required>
<option value="">請選擇</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</td>
<td>班級</td>
<td>
<select name="cla" required>
<option value="">請選擇</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
</select>
</td>
<td>座號</td>
<td>
<select name="sno" required>
<option value="">請選擇</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
</select>
</tr>
<tr>
<td>密碼</td>
<td>
<input name="pwd" type="password" maxlength="10" required>
</td>
</tr>
<tr>
<td>
<input type="submit" value="登入網站" name="ok">
</td>
</tr>
</table>
</form>
</article>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</body>
</html>
-------------------------------------------------------------------------- login.php --v2 加上session
<?php
session_start();
//$_SESSION['sid']="";
if (isset($_POST['pwd']))
{
$conn=mysqli_connect("localhost","root","db123456","kkdb");
if (mysqli_connect_errno($conn))
die("無法連線!");
mysqli_set_charset($conn,"utf8");
$sql="SELECT * FROM tblstu WHERE gra='".$_POST['gra']."' AND cla='".$_POST['cla']."' AND sno='".$_POST['sno']."' AND pwd='".$_POST['pwd']."'";
$rslt=mysqli_query($conn,$sql);
$row=mysqli_fetch_assoc($rslt);
//echo gettype($row['sid']);
if (is_null($row['sid']))
{
?>
<script language="javascript">;
alert("沒有註冊資料!請先註冊...");
window.location.href="add.html"
</script>;
<?php
}
else
{
$_SESSION['sid']=$row['sid'];
header("Location:menu.html");
}
}
?>
----------------------------------------------------------------------------------------- login.php
# vi /var/www/html/login.php
<?php
if (isset($_POST['pwd'])){
$conn=mysqli_connect("localhost","root","db123456","kkdb");
if (mysqli_connect_errno($conn))
die("無法連線!");
mysqli_set_charset($conn,"utf8");
$sql="SELECT * FROM tblstu WHERE gra='".$_POST['gra']."' AND cla='".$_POST['cla']."' AND sno='".$_POST['sno']."' AND pwd='".$_POST['pwd']."'";
$rslt=mysqli_query($conn,$sql);
$cnt=mysqli_num_rows($rslt);
if ($cnt>0){
header("Location:menu.html");
}
else{
?>
<script language="javascript">;
alert("沒有註冊資料!請先註冊...");
window.location.href="add.html"
</script>;
<?php
}
}
?>
-----------------------------------------------------------------------------------------
MariaDB [kkdb]> create table tblsr (sid int, chid int, scr tinyint);
MariaDB [kkdb]> show create table tblsr \G;
*************************** 1. row ***************************
Table: tblsr
Create Table: CREATE TABLE `tblsr` (
`sid` int(11) DEFAULT NULL,
`chid` int(11) DEFAULT NULL,
`scr` tinyint(4) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
MariaDB [kkdb]> create table tblch (chid int primary key auto_increment, gra varchar(1), chpr varchar(30));
MariaDB [kkdb]> INSERT INTO tblch (gra, chpr) VALUES ('1', '第一 章 資訊科技導論');
MariaDB [kkdb]> create table tblexam (qid int primary key auto_increment, chid int, qus varchar(100), opt1 varchar(25), opt2 varchar(25), opt3 varchar(25), opt4 varchar(25), ans varchar(1));
MariaDB [kkdb]> INSERT INTO tblexam (gra, chpr, qus, opt1, opt2, opt3, opt4, ans) VALUES ('1', '第一 章 資訊科技導論', '訓練飛行員可以運用何種電腦科技來避免人員與飛機的實際損失?', '電腦輔助設計(CAD)', '電腦輔助製造(CAM)', '無線射頻辨識(RFID)', '虛擬實境(VR)', 'D');
MariaDB [kkdb]> select * from tblexam;
----------------------------------------------------------- addqus.php V2
<?php
if (isset($_POST['qus']))
{
$conn=mysqli_connect("localhost","root","db123456","kkdb");
if (mysqli_connect_errno($conn))
die("無法連線!");
mysqli_set_charset($conn,"utf8");
$sql="INSERT INTO tblexam (chid, qus, opt1, opt2, opt3, opt4, ans) VALUES ('".$_POST['chpr']."','".$_POST['qus']."','".$_POST['opt1']."','".$_POST['opt2']."','".$_POST['opt3']."','".$_POST['opt4']."','".$_POST['ans']."')";
$rslt=mysqli_query($conn,$sql);
header("Location:addqus.php");
}
else
{
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
$conn=mysqli_connect("localhost","root","db123456","kkdb");
if (mysqli_connect_errno($conn))
die("無法連線!");
mysqli_set_charset($conn,"utf8");
$sql="SELECT chid,chpr FROM tblch ORDER BY chpr";
$rslt=mysqli_query($conn,$sql);
?>
<header>
<nav>修改密碼 線上測驗 療聊園地</nav>
<h1>新增題目</h1>
</header>
<form action="addqus.php" method="post">
<table>
<tr>
<td>章節名</td>
<td>
<select name="chpr" required>
<option value="">請選擇</option>
<?php
while ($row=mysqli_fetch_assoc($rslt) )
echo("<OPTION VALUE=".$row['chid'].">".$row['chpr']."</OPTION>");
?>
</select>
</td>
</tr>
<tr>
<td>題目</td>
<td>
<input name="qus" type="text" maxlength="100" size="60" required>
</td>
</tr>
<td>選項1</td>
<td>
<input name="opt1" type="text" maxlength="25" required>
</td>
<td>選項2</td>
<td>
<input name="opt2" type="text" maxlength="25" required>
</td>
<td>選項3</td>
<td>
<input name="opt3" type="text" maxlength="25" required>
</td>
<td>選項4</td>
<td>
<input name="opt4" type="text" maxlength="25" required>
</td>
</tr>
<tr>
<td>答案</td>
<td>
<select name="ans" required>
<option value="">請選擇</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" value="新增題目" name="ok">
</td>
</tr>
</table>
</form>
<p>
<h1>以下列出所有已收錄題目:</h1>
<?php
$sql="SELECT * FROM tblexam ORDER BY chid, qid";
$rslt=mysqli_query($conn,$sql);
while ($row=mysqli_fetch_assoc($rslt))
{
echo $row['qid'],"-->", $row['chid'];
echo "</br>";
echo $row['qus'], $row['opt1'], $row['opt2'], $row['opt3'], $row['opt4'];
echo "</br>";
echo $row['ans'];
echo "</br>";
echo "<p>";
};
?>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</body>
</html>
<?php
}
?>
----------------------------------------------------------- addqus.php
<?php
if (isset($_POST['qus']))
{
$conn=mysqli_connect("localhost","root","db123456","kkdb");
if (mysqli_connect_errno($conn))
die("無法連線!");
mysqli_set_charset($conn,"utf8");
$sql="INSERT INTO tblexam (chid, qus, opt1, opt2, opt3, opt4, ans) VALUES ('".$_POST['chpr']."','".$_POST['qus']."','".$_POST['opt1']."','".$_POST['opt2']."','".$_POST['opt3']."','".$_POST['opt4']."','".$_POST['ans']."')";
$rslt=mysqli_query($conn,$sql);
header("Location:addqus.php");
}
else
{
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
$conn=mysqli_connect("localhost","root","db123456","kkdb");
if (mysqli_connect_errno($conn))
die("無法連線!");
mysqli_set_charset($conn,"utf8");
$sql="SELECT chid,chpr FROM tblch ORDER BY chpr";
$rslt=mysqli_query($conn,$sql);
?>
<header>
<h1>新增題目</h1>
<nav>修改密碼 線上測驗 療聊園地</nav>
</header>
<form action="addqus.php" method="post">
<table>
<tr>
<td>章節名</td>
<td>
<select name="chpr" required>
<option value="">請選擇</option>
<?php
while ($row=mysqli_fetch_assoc($rslt) )
echo("<OPTION VALUE=".$row['chid'].">".$row['chpr']."</OPTION>");
?>
</select>
</td>
</tr>
<tr>
<td>題目</td>
<td>
<input name="qus" type="text" maxlength="100" size="60" required>
</td>
</tr>
<td>選項1</td>
<td>
<input name="opt1" type="text" maxlength="25" required>
</td>
<td>選項2</td>
<td>
<input name="opt2" type="text" maxlength="25" required>
</td>
<td>選項2</td>
<td>
<input name="opt2" type="text" maxlength="25" required>
</td>
<td>選項3</td>
<td>
<input name="opt3" type="text" maxlength="25" required>
</td>
<td>選項4</td>
<td>
<input name="opt4" type="text" maxlength="25" required>
</td>
</tr>
<td>答案</td>
<td>
<select name="ans" required>
<option value="">請選擇</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" value="新增題目" name="ok">
</td>
</tr>
</table>
</form>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</body>
</html>
<?php
}
?>
------------------------------------------------------------------- exam.php
<?php
if (isset($_POST['chpr']))
{
$conn=mysqli_connect("localhost","root","db123456","kkdb");
if (mysqli_connect_errno($conn))
die("無法連線!");
mysqli_set_charset($conn,"utf8");
$sql="SELECT * FROM tblexam where chid='1' ORDER BY RAND() LIMIT 10";
$rslt=mysqli_query($conn,$sql);
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<header>
<nav>修改密碼 線上測驗 療聊園地</nav>
<h1>線上測驗</h1>
<h2></h2>
</header>
<form action="check.php" method="post">
<?php
$i=1;
while ($row=mysqli_fetch_assoc($rslt))
{
?>
<input type="hidden" name=q<?php echo $i ?> value="<?php echo $row['ans'] ?>">
<font size="4" color="Brown"><?php echo $i ?>.</font>
<font size="4" color="DarkBlue"><?php echo $row['qus'] ?></font></br>
<input type="radio" name="rdo<?php echo $i ?>" value="A"><?php echo $row['opt1'] ?>
<input type="radio" name="rdo<?php echo $i ?>" value="B"><?php echo $row['opt2'] ?>
<input type="radio" name="rdo<?php echo $i ?>" value="C"><?php echo $row['opt3'] ?>
<input type="radio" name="rdo<?php echo $i ?>" value="D"><?php echo $row['opt4'] ?>
<p>
<?php
$i++;
}
?>
<input type="submit" value="我答完了" name="ok">
</form>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</body>
</html>
<?php
}
else
{
?>
<!DOCTYPE html>
<html>
<head>
<title>郭老師資訊學園</title>
<meta charset="utf-8">
<link href="WebStyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php
$conn=mysqli_connect("localhost","root","db123456","kkdb");
if (mysqli_connect_errno($conn))
die("無法連線!");
mysqli_set_charset($conn,"utf8");
$_SESSION['gra']='7';
$sql="SELECT chid,chpr FROM tblch WHERE gra='".$_SESSION['gra']."' ORDER BY chpr";
$rslt=mysqli_query($conn,$sql);
?>
<header>
<nav>修改密碼 線上測驗 療聊園地</nav>
<h1>選擇測驗範圍</h1>
</header>
<form action="exam.php" method="post">
<table>
<tr>
<td>章節名</td>
<td>
<select name="chpr" required>
<option value="">請選擇</option>
<?php
while ($row=mysqli_fetch_assoc($rslt) )
echo("<OPTION VALUE=".$row['chid'].">".$row['chpr']."</OPTION>");
?>
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" value="確定範圍" name="ok">
</td>
</tr>
</table>
</form>
<footer><p>Copyright © 2019 GuoChin All Rights Reserved</p></footer>
</body>
</html>
<?php
}
?>
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------