HTML+PHP搭建一个生物数据增删查改网站
目录
HTML+PHP搭建一个生物数据增删查改网站
1、使用说明
2、代码
主要分为一下两个部分介绍这个project:
1、使用说明
自己写了个比较简单的说明书,下载网站如下:
HTML+PHP搭建一个生物数据增删查改网站使用说明书-PHP文档类资源-CSDN文库
所以我就简单截图一下文档的内容(如果你没有积分下载原文件的话)。
?
?
?
?
2、代码
代码也上传到CSDN上了,下载网站如下,简单改一下数据库链接就可以直接运行,数据库文件已经导出为sql格式存放在mysql文件夹下:
使用HTML+PHP搭建一个生物数据增删查改网站代码-PHP文档类资源-CSDN文库
?将几个主要的php文件展示如下(如果你没有积分下载可以看看这个):
login.php
<?php
function check_input($value)
{
if(get_magic_quotes_gpc()){ //获取当前 magic_quotes_gpc 的配置选项 当 magic_quotes_gpc=On 时,如果输入的数据有单引号(’)、双引号(”)、反斜线()与 NUL(NULL 字符)等字符都会被加上反斜线
$value = htmlspecialchars(trim($value));//去掉空白
} else {
$value = addslashes(htmlspecialchars(trim($value))); //手动加上转义反斜线
}
return $value;
}
session_start();
if(isset($_GET['logout'])&&$_GET['logout']){
session_destroy();
echo "
<script>
alert('Successfully Logged out!');
window.location.href = 'index.html' ;
</script>
";
exit;
}
$username = $_POST["Username"];
$password = $_POST["Password"];
$accounttype = $_POST["Accounttype"];
if($username == "" || $password == "")
{
echo "
<script>
alert('None of the information should be empty');
window.location.href = 'index.html' ;
</script>
";
}
else{
$conn = @mysqli_connect("localhost","admin1","admin1","homework1");
if (!$conn){
die("Connecting database error!" . mysqli_connect_error());
}
$password = MD5($password);
$check_query = mysqli_query($conn,"select * from user where username='$username' and password='$password' and accounttype='$accounttype' limit 1 for update");
$check= mysqli_fetch_array($check_query);
if ($check['accounttype'] == "Administrator"){
echo "<script>
alert('Welcome back administor $username!');
window.location.href = 'adminpage.html' ;
</script>";}
elseif($check['accounttype'] == "User"){
echo "
<script>
alert('Welcome back user $username!');
window.location.href = 'userpage.html' ;
</script>
";}
else{
mysqli_query($conn,"commit");
mysqli_close($conn);
echo "
<script>
alert('Login failed with username : $accounttype!');
window.location.href = 'index.html' ;
</script>";
}
exit();
?>
register.php
<?php
function check_input($value)
{
if(get_magic_quotes_gpc()){
$value = htmlspecialchars(trim($value));
} else {
$value = addslashes(htmlspecialchars(trim($value)));
}
return $value;
}
$username = $_POST["username"];
$password = $_POST["password"];
$password2 = $_POST["password2"];
$accounttype = $_POST["accounttype"];
if($username == "" || $password == "" || $password2 == "" )
{
echo "
<script>
alert('None of the information should be empty');
window.location.href = 'register.html' ;
</script>
";
}
else if($password != $password2)
{
echo "
<script>
alert('Password confirmation error!');
window.location.href = 'register.html' ;
</script>
";
}
else
{
//connect to mysql
$conn = @mysqli_connect("localhost","admin1","admin1","homework1");
if (!$conn){
die("Connecting database error!".mysqli_error($conn));
}
$username=check_input($username);
$password = MD5($password);//以MD5散列值存储密码
$accounttype = check_input($accounttype);
mysqli_query($conn,"begin");
$check_query = mysqli_query($conn,"select * from user where name='$username' limit 1");
//if(mysqli_fetch_array($check_query,MYSQLI_BOTH)){
if($check_query){
echo "
<script>
alert('Error, username existed.Please try again with a different username.');
window.location.href = 'register.html' ;
</script>
";
exit;
}
$sql = "INSERT INTO user(username,password,accounttype) VALUES('$username','$password','$accounttype')";
if(mysqli_query($conn,$sql)){
mysqli_query($conn,"commit");
mysqli_close($conn);
echo "
<script>
alert('Succesfully Registered');
window.location.href = 'index.html' ;
</script>
";
exit();
} else {
echo 'Fail writing database.',mysqli_error($conn),'<br />';
echo 'Click here to <a href="javascript:history.back(-1);">go back</a> and retry';
mysqli_query($conn,"rollback");
mysqli_close($conn);
exit();
}
}
?>
userpage.php ?
<?php
echo "<html><head>
<meta charset=\"utf-8\">
<link rel=\"stylesheet\" type=\"text/css\" href=\"./styles.css\"></head><body><div class=\"bg-img\" style=\"overflow-y:auto\"> ";
$conn = @mysqli_connect("localhost","admin1","admin1","homework1");
if (!$conn){
die("Connecting database error!" . mysqli_error($conn));
}
mysqli_query($conn,"begin");
$Entry = $_POST["Entry"];
$Entry_name = $_POST["Entryname"];
$Gene_names = $_POST["Genenames"];
$species = $_POST["species"];
$sql="select * from prot";
$res=mysqli_query($conn,$sql);
$rows=mysqli_affected_rows($conn);//获取行数
$colums=mysqli_num_fields($res);//获取列数
echo "本网站数据库共计".$rows."行, 共计".$colums."列。前10行数据动态展示如下:<br/>";
echo"数据库前10行数据动态展示:<br />";
echo "<table border=1><tr>
<td>ID</td>
<td>Entry</td>
<td>Entryname</td>
<td>uniport_Status</td>
<td>Protein_names</td>
<td>Genenames</td>
<td>Organism</td>
<td>Length</td>
<td>Species</td>
</tr>";
$i=0;
while($ro = mysqli_fetch_array($res))
{
if($i<10)
{
echo "<tr>
<td>".$ro["ID"]."</td>
<td>".$ro["Entry"]."</td>
<td>".$ro["Entry_name"]."</td>
<td>".$ro["uniport_Status"]."</td>
<td>".$ro["Protein_names"]."</td>
<td>".$ro["Gene_names"]."</td>
<td>".$ro["Organism"]."</td>
<td>".$ro["Length"]."</td>
<td>".$ro["species"]."</td></tr>";
$i++;
} }
echo"</table>";
echo "<br />" ;
// $result5 = mysqli_query($conn,"SELECT * FROM prot where species='$species'and Entry='$Entry'and Entry_name='$Entry_name' and Gene_names='$Gene_names'");
echo"依据Entry&Entry_name&Gene_name&Species查询结果如下";
echo"<table border=\"1\"><tr>
<th>Entry</th>
<th>Entry_name</th>
<th>Gene_names</th>
<th>uniport_Status</th>
<th>Protein_names</th>
<th>Organism</th>
<th>Length</th>
<td>Species</td>
</tr>";
if($species!= ""){
$sql = "SELECT * FROM prot where species='$species'";
if($Entry != ""){
$sql = "SELECT * FROM prot where species='$species'and Entry='$Entry'";
if($Entry_name != ""){
$sql="SELECT * FROM prot where species='$species'and Entry='$Entry'and Entry_name='$Entry_name' ";
if($Gene_names!= ""){
$sql="SELECT * FROM prot where species='$species'and Entry='$Entry'and Entry_name='$Entry_name' and Gene_names='$Gene_names'";
}else{
//$sql="SELECT * FROM prot where species='$species'and Entry='$Entry'and Entry_name='$Entry_name' and Gene_names='$Gene_names'";
echo "请输入至少一个要查找的字段";
}
}
}
}
//echo "$sql";
$result5 = mysqli_query($conn,$sql);
while($row4 = mysqli_fetch_array($result5))
{
echo "<tr>
<td>".$row4["Entry"]."</td>
<td>".$row4["Entry_name"]."</td>
<td>".$row4["Gene_names"]."</td>
<td>".$row4["uniport_Status"]."</td>
<td>".$row4["Protein_names"]."</td>
<td>".$row4["Organism"]."</td>
<td>".$row4["Length"]."</td>
<td>".$row4["species"]."</td></tr>";
}
echo"</table>";
echo "<br />" ;
$result1 = mysqli_query($conn,"SELECT * FROM prot where Entry='$Entry'");
echo"依据Entry查询结果如下(查询结果超过20条只返回前20条数据):<br />";
echo "<table border=1><tr>
<td>Entry</td>
<td>Entryname</td>
<td>uniport_Status</td>
<td>Protein_names</td>
<td>Genenames</td>
<td>Organism</td>
<td>Length</td>
<td>Species</td>
</tr>";
$i1=0;
while($row = mysqli_fetch_array($result1))
{
if($row["Entry"] != "")
{
if($i1<20)
{
echo "<tr>
<td>".$row["Entry"]."</td>
<td>".$row["Entry_name"]."</td>
<td>".$row["uniport_Status"]."</td>
<td>".$row["Protein_names"]."</td>
<td>".$row["Gene_names"]."</td>
<td>".$row["Organism"]."</td>
<td>".$row["Length"]."</td>
<td>".$row["species"]."</td></tr>";
$i1++;
} } }
echo"</table>";
echo "<br />" ;
$result2 = mysqli_query($conn,"SELECT * FROM prot where Entry_name = '$Entry_name'");
echo"依据Entry name查询结果如下(查询结果超过20条只返回前20条数据):<br />";
echo"<table border=1><tr>
<th>Entry_name</th>
<th>Entry</th>
<th>uniport_Status</th>
<th>Protein_names</th>
<th>Gene_names</th>
<th>Organism</th>
<th>Length</th>
<td>Species</td>
</tr>";
$i2=0;
while($row1 = mysqli_fetch_array($result2))
{
if($row1["Entry_name"] != "")
{
if($i2<20)
{
echo "<tr>
<td>".$row1["Entry_name"]."</td>
<td>".$row1["Entry"]."</td>
<td>".$row1["uniport_Status"]."</td>
<td>".$row1["Protein_names"]."</td>
<td>".$row1["Gene_names"]."</td>
<td>".$row1["Organism"]."</td>
<td>".$row1["Length"]."</td>
<td>".$row1["species"]."</td></tr>";
$i2++;
} } }
echo"</table>";
echo "<br />" ;
$result3 = mysqli_query($conn,"SELECT * FROM prot where Gene_names='$Gene_names'");
echo"依据Gene_names查询结果如下(查询结果超过20条只返回前20条数据):<br />";
echo"<table border=\"1\"><tr>
<th>Gene_names</th>
<th>Entry</th>
<th>Entry_name</th>
<th>uniport_Status</th>
<th>Protein_names</th>
<th>Organism</th>
<th>Length</th>
<td>Species</td>
</tr>";
$i3=0;
while($row2 = mysqli_fetch_array($result3))
{
if($row2["Gene_names"] != "")
{
if($i3<20)
{
echo "<tr>
<td>".$row2["Gene_names"]."</td>
<td>".$row2["Entry"]."</td>
<td>".$row2["Entry_name"]."</td>
<td>".$row2["uniport_Status"]."</td>
<td>".$row2["Protein_names"]."</td>
<td>".$row2["Organism"]."</td>
<td>".$row2["Length"]."</td>
<td>".$row2["species"]."</td></tr>";
$i3++;
}
} }
echo"</table>";
echo "<br />" ;
$result4 = mysqli_query($conn,"SELECT * FROM prot where species='$species'");
echo"依据Species查询结果如下(查询结果超过20条只返回前20条数据)";
echo"<table border=\"1\"><tr>
<th>ID</th>
<td>Species</td>
<th>Entry</th>
<th>Gene_names</th>
<th>Entry_name</th>
<th>uniport_Status</th>
<th>Protein_names</th>
<th>Organism</th>
<th>Length</th>
</tr>";
$i4=0;
while($row3 = mysqli_fetch_array($result4))
{
if($row3["species"] != "")
{
if($i4<20)
{
echo "<tr>
<td>".$row3["ID"]."</td>
<td>".$row3["species"]."</td>
<td>".$row3["Entry"]."</td>
<td>".$row3["Gene_names"]."</td>
<td>".$row3["Entry_name"]."</td>
<td>".$row3["uniport_Status"]."</td>
<td>".$row3["Protein_names"]."</td>
<td>".$row3["Organism"]."</td>
<td>".$row3["Length"]."</td></tr>";
$i4++;
}} }
echo"</table>";
echo '<br><a href="index.html">Log out</a><br />';
echo "<br />" ;
echo "<br />" ;
echo "</div></body></html>";
mysqli_query($conn,"commit");
?>
?adminpage.php
<?php
echo "<html><head>
<meta charset=\"utf-8\">
<link rel=\"stylesheet\" type=\"text/css\" href=\"./styles.css\"></head><body><div class=\"bg-img\" style=\"overflow-y:auto\"> ";
echo "Weclcome administrator! This is your workspace.";
echo "<br>";
echo"<form action=\"adminsc.php\" method=\"POST\">
Entry:<br>
<input type=\"text\" name=\"Entry\">
<br>
Entryname:<br>
<input type=\"text\" name=\"Entryname\">
<br>
uniport_Status:<br>
<input type=\"text\" name=\"uniport_Status\">
<br>
Protein_names:<br>
<input type=\"text\" name=\"Protein_names\">
<br>
Genenames:<br>
<input type=\"text\" name=\"Genenames\">
<br>
Organism:<br>
<input type=\"text\" name=\"Organism\">
<br>
Length:<br>
<input type=\"text\" name=\"Length\">
<br>
Species:<br>
<input type=\"text\" name=\"Species\">
<br>
<input type=\"radio\" name=\"op\" value=\"0\" /> Create
<input type=\"radio\" name=\"op\" value=\"1\" /> Delete
<input type=\"radio\" name=\"op\" value=\"2\" /> Alter
<br>
<input type=\"submit\" value=\"Submit\">
</form> ";
echo '<a href="adminpage.html">Back to search</a><br />';
echo "<br>";
echo '<br><a href="index.html">Log out</a><br />';
echo "<br>";
$conn = @mysqli_connect("localhost","admin1","admin1","homework1");
if (!$conn){
die("Connecting database error!" . mysqli_error());
}
mysqli_query($conn,"begin");
$result1 = mysqli_query($conn,"SELECT * FROM prot");
$sql="select * from prot";
$res=mysqli_query($conn,$sql);
$rows=mysqli_affected_rows($conn);//获取行数
$colums=mysqli_num_fields($res);//获取列数
echo "Website数据库共计".$rows."行, ".$colums."列。数据如下:<br/>";
echo "<table border=1><tr>
<td>ID</td>
<td>Entry</td>
<td>Entryname</td>
<td>uniport_Status</td>
<td>Protein_names</td>
<td>Genenames</td>
<td>Organism</td>
<td>Length</td>
<td>Species</td>
</tr>";
while($row=mysqli_fetch_row($res)){
echo "<tr>";
for($i=0; $i<$colums; $i++){
echo "<td>$row[$i]</td>";
}
echo "</tr>";
}
echo"</table><br />";
mysqli_query($conn,"commit");
echo "</div></body></html>"
?>
adminprot.php
<?php
$Entry = $_POST["Entry"];
$Entry_name = $_POST["Entryname"];
$Gene_names = $_POST["Genenames"];
$uniport_Status = $_POST['uniport_Status'];
$Protein_names = $_POST['Protein_names'];
$Organism = $_POST['Organism'];
$Length = $_POST['Length'];
$species = $_POST["species"];
$ID = NULL;
$op = $_POST["op"];
if($op == "3") {
echo "
<script>
window.location.href = 'adminpage.html' ;
</script>";
}
if($Entry == "")
{
echo "
<script>
alert('None of the Entry information should be empty');
window.location.href = 'adminpage1.html' ;
</script>
";
}
else
{
//connect to mysql
$conn = @mysqli_connect("localhost","admin1","admin1","homework1");
if (!$conn){
die("Connecting database error!" . mysqli_connect_error($conn));
}
mysqli_query($conn,"begin");
$check_query = mysqli_query($conn,"select * from prot where Entry='$Entry'");
$result=mysqli_fetch_array($check_query);
if($op == "0")
{
if($Entry == $result['Entry']){
echo "
<script>
alert('Error, Entry existed.Please try again with a different Entry.');
window.location.href = 'adminpage1.html' ;
</script>
";
exit;
}
$sql2 = "INSERT INTO prot(Entry, Entry_name, uniport_Status, Protein_names, Gene_names, Organism, Length, species)
VALUES ('$Entry', '$Entry_name', '$uniport_Status', '$Protein_names', '$Gene_names', '$Organism', '$Length', '$species')";
//$sql = "INSERT INTO prot('Entry','Entry_name','uniport_Status','Protein_names','Gene_names','Organism','Length','species')
//VALUES('$Entry','$Entry_name','$uniport_Status','$Protein_names','$Gene_names','$Organism','$Length','$species')";
if(mysqli_query($conn,$sql2)){
mysqli_query($conn,"commit");
mysqli_close($conn);
echo "
<script>
alert('Creat recrode succeed!');
window.location.href = 'adminpage1.html' ;
</script>
";
exit();
}
else {
echo 'Fail writing database.',mysqli_error($conn),'<br />';
echo 'Click here to <a href="javascript:history.back(-1);">Go back</a> and retry';
mysqli_query($conn,"rollback");
mysqli_close($conn);
exit();
}
}
if($op == "1"){
$sql3 = "DELETE FROM prot WHERE Entry='$Entry'";
if(mysqli_query($conn,$sql3)){
mysqli_query($conn,"commit");
mysqli_close($conn);
echo "
<script>
alert('Entry Recode delete succeed!');
window.location.href ='adminpage1.html' ;
</script>
";
exit();
} else {
echo 'Fail writing database.',mysqli_error($conn),'<br />';
echo 'Click here to <a href="javascript:history.back(-1);">Go back</a> and retry';
mysqli_query($conn,"rollback");
mysqli_close($conn);
exit();
}
}
if($op == "2") {
if($Entry_name == "") {$Entry_name=$result['Entry_name'];}
if($Gene_names == "") {$Gene_names=$result['Gene_names'];}
if($uniport_Status == "") {$uniport_Statuso=$result['uniport_Status'];}
if($Protein_names == "") {$Protein_names=$result['Protein_names'];}
if($Length == "") {$Length=$result['Length'];}
if($Organism == "") {$Organism=$result['Organism'];}
if($species == "") {$species=$result['species'];}
$sql4 = "UPDATE prot SET Entry_name='$Entry_name',Gene_names='$Gene_names',uniport_Status='$uniport_Status',Protein_names='$Protein_names',Length='$Length',Organism='$Organism',species='$species' WHERE Entry='$Entry'";
if(mysqli_query($conn,$sql4)){
mysqli_query($conn,"commit");
mysqli_close($conn);
echo "
<script>
alert('Datebase Alter Succeed!');
window.location.href ='adminpage1.html' ;
</script>
";
exit();
} else {
echo 'Fail Alter Database.',mysqli_error($conn),'<br />';
echo 'Click here to <a href="javascript:history.back(-1);">Go back</a> and retry';
mysqli_query($conn,"rollback");
mysqli_close($conn);
exit();
}
}
}
?>
?styles.css
body {
font-family: 'Montserrat', sans-serif;
text-rendering : optimizeLegibility;
-webkit-font-smoothing : antialiased;
}
#login-bg.container-fluid {
padding: 0;
height: 100%;
position: absolute;
}
/* Background image an color divs*/
.bg-img {
min-width: 50%;
width: 100%;
vertical-align: top;
padding: 0;
margin-left: 0;
height: 100%;
display: inline-block;
overflow: hidden;
}
.bg-img {
background-image: url(./bg-image.jpeg);
background-size: cover;
}
.bg-img1 {
min-width: 50%;
width: 100%;
vertical-align: top;
padding: 0;
margin-left: 0;
height: 100%;
display: inline-block;
overflow: hidden;
}
.bg-img1 {
background-image: url(./bg-image.jpeg);
background-size: cover;
}
#login{
padding-top: 10%;
text-align: center;
text-transform: uppercase;
}
.login {
width: 100%;
height: 500px;
background-color: #fff;
padding: 15px;
padding-top: 30px;
}
.login h1 {
margin-top: 30px;
font-weight: bold;
font-size: 60px;
letter-spacing: 3px;
}
.login form {
max-width: 420px;
margin: 30px auto;
}
.login .btn {
border-radius: 50px;
text-transform: uppercase;
font-weight: bold;
letter-spacing: 2px;
font-size: 20px;
padding: 14px;
background-color: #FFB6C1;
border: #FFB6C1;
}
.form-group input {
font-size: 20px;
font-weight: lighter;
border: none;
background-color: #F0F0F0;
color: #465347!important;
padding: 26px 30px;
border-radius: 50px;
transition : 0.2s;
}
/* Form check styles*/
.form-check {
padding: 0;
text-align: left;
}
.form-check label {
vertical-align: top;
padding-top: 5px;
padding-left: 5px;
font-size: 15px;
color: #606060;
font-size: 14px;
}
.forgot-password {
text-align: right;
float: right;
font-weight: bold;
}
.forgot-password a {
color: #808080;
opacity: 1;
}
.forgot-password a:hover {
opacity: 1;
}
/* Switch styles */
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 30px;
}
/* Hide default HTML checkbox */
.switch input {display:none;}
/* The slider */
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #F0F0F0;
-webkit-transition: .4s;
transition: .4s;
border-radius: 30px;
}
.slider:before {
position: absolute;
content: "";
height: 22px;
width: 22px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: #FFB6C1;
}
input:focus + .slider {
box-shadow: 0 0 1px ##FFB6C1;
}
input:checked + .slider:before {
-webkit-transform: translateX(30px);
-ms-transform: translateX(30px);
transform: translateX(30px);
}
/* Media queries */
@media(max-width: 500px) {
.bg-img , .bg-color {
min-width: 100%;
height: 50%;
margin: 0;
}
.forgot-password {
text-align: right;
float: left;
padding: 20px 0;
}
#login {
padding-top: 50px;
}
}
这代码没有写很多注释,也没有去polish逻辑关系,几乎是不带脑子完成任务,所以写得不好的地方,看不懂的地方欢迎大家评论留言,我都回复的。
|