链接phpmyadmin 一直这样,是少表单 还是 能符上代码么 新手小白

oiuhp 2020-05-15 07:32:38
500 - 内部服务器错误。您查找的资源存在问题,因而无法显示。

php文件夹
connect.php
?php
$server="localhost";//主机
$db_username="root";//你的数据库用户名
$db_password="root";//你的数据库密码

$con = mysql_connect($server,$db_username,$db_password);//链接数据库
if(!$con){
die("can't connect".mysql_error());//如果链接失败输出错误
}

mysql_select_db('test',$con);//选择数据库(test是数据库名称)
//字符转换,读库
login.php
<?PHP
header("Content-Type: text/html; charset=utf8");

if(!isset($_POST["submit"])){
exit("非法访问!");
}//检测是否有submit操作

include('connect.php');//链接数据库

$name = $_POST['name'];//post获得用户名表单值
$passowrd = MD5($_POST['password']);//post获得用户密码单值,使用MD5加密,不可逆

if ($name && $passowrd){//如果用户名和密码都不为空
$sql = "select * from admin where username = '$name' and password='$passowrd'";//检测数据库是否有对应的username和password的sql
$result = mysql_query($sql);//执行sql
$rows=mysql_num_rows($result);//返回一个数值
if($rows){//0 false 1 true
//登录成功
session_start();//启动Session
$_SESSION['name'] = $_POST['name'];
header("refresh:0;url=sucess.php");//如果成功跳转至sucess.php页面
exit;
}else{
echo "用户名或密码错误,请重新登录!";
echo "
<script>
setTimeout(function(){window.location.href='../login.html';},1000);
</script>

";//如果错误使用js 1秒后跳转到登录页面重试;
}

}else{//如果用户名或密码有空
echo "用户名或密码填写不完整,请重新登录!";
echo "
<script>
setTimeout(function(){window.location.href='../login.html';},1000);
</script>";
//如果错误使用js 1秒后跳转到登录页面重试;
}

mysql_close();//关闭数据库
?>

<?php
header("Content-Type: text/html; charset=utf8");

if(!isset($_POST['submit'])){
exit("错误执行");
}//判断是否有submit操作

$name=$_POST['name'];//post获取表单里的name
$password=MD5($_POST['password']);//post获取表单里的password,使用MD5加密,不可逆

include('connect.php');//链接数据库

$sql = "select username from admin where username = '$name'";//SQL语句
$result = mysql_query($sql);//执行SQL语句
$num = mysql_num_rows($result);//统计执行结果影响的行数
if ($num) {//如果已经存在该用户
echo "<script>alert('温馨提示:用户存在!'); history.go(-1);</script>";
} else {
$q="insert into admin(id,username,password) values (null,'$name','$password')";//向数据库插入表单传来的值的sql
$reslut=mysql_query($q,$con);//执行sql
if (!$reslut){
die('Error: ' . mysql_error());//如果sql执行失败输出错误
}else{
echo "注册成功";//成功输出注册成功
echo "
<script>
setTimeout(function(){window.location.href='../login.html';},1000);
</script>";
//如果注册成功使用js 1秒后跳转到登录页面;
}
}
mysql_close($con);//关闭数据库
?>
result.php
<?php
header("Content-Type: text/html; charset=utf8");

if(!isset($_POST['submit'])){
exit("错误执行");
}//判断是否有submit操作

$name=$_POST['name'];//post获取表单里的name
$password=MD5($_POST['password']);//post获取表单里的password,使用MD5加密,不可逆

include('connect.php');//链接数据库

$sql = "select username from admin where username = '$name'";//SQL语句
$result = mysql_query($sql);//执行SQL语句
$num = mysql_num_rows($result);//统计执行结果影响的行数
if ($num) {//如果已经存在该用户
echo "<script>alert('温馨提示:用户存在!'); history.go(-1);</script>";
} else {
$q="insert into admin(id,username,password) values (null,'$name','$password')";//向数据库插入表单传来的值的sql
$reslut=mysql_query($q,$con);//执行sql
if (!$reslut){
die('Error: ' . mysql_error());//如果sql执行失败输出错误
}else{
echo "注册成功";//成功输出注册成功
echo "
<script>
setTimeout(function(){window.location.href='../login.html';},1000);
</script>";
//如果注册成功使用js 1秒后跳转到登录页面;
}
}
mysql_close($con);//关闭数据库
?>
test.php
<?php

?>
login.html
<!DOCTYPE html>
<html lang="cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link href="css/login.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="js/login.js"></script>
</head>
<body>
<div class="y">
</div>
<div class="login">
<div class="message"></div>
<div id="darkbannerwrap"></div>
<form name="login" action="php/login.php" method="post" onsubmit="return check()">
<input name="name" id="name" placeholder="请输入登录帐号" type="text" required="required" maxlength="16">
<hr class="hr15">
<input name="password" id="password" placeholder="请输入登录密码" type="password" required="required" maxlength="16">
<hr class="hr15">
<input value="登录" style="width:100%;" type="submit" name="submit">
<a href="result.html">注册</a>
<a href="#">忘记密码</a>
<hr class="hr20">
</form>
</div>

</body>
</html>
result.html
<!DOCTYPE html>
<html lang="cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link href="css/result.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="js/result.js"></script>
</head>
<body>
<div class="login">
<div class="message"></div>
<div id="darkbannerwrap"></div>
<form name="result" action="php/result.php" method="post" onsubmit="return check()">
<input name="name" id="name" placeholder="请输入帐号" type="text" required="required" maxlength="16">
<hr class="hr15">
<input name="password" id="password" placeholder="请输入密码" type="password" required="required" maxlength="16">
<hr class="hr15">
<input name="pwd" id="pwd" placeholder="请再次输入密码" type="password" required="required" maxlength="16">
<hr class="hr15">
<input value="注册" style="width:100%;" type="submit" name="submit">
<a href="login.html">返回登录</a>
<a href="#">忘记密码</a>
<hr class="hr20">
</form>

</body>
</html>
...全文
87 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
野泽雅子 2020-05-17
  • 打赏
  • 举报
回复
问题没有暴露出来啊?截张图

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧