真的wo'shi我试过很多方法,看过很多视频,明明是一样的代码,为什么我的都是不成功,别人的我不知道...很烦啊,未成功提示框也不显示错误点在哪,感觉要崩溃了0_0
login.php:
<!DOCTYPE>
<html>
<head>
<meta charset="utf-8">
<title>登录</title>
<script>
function init(){
if(myform.username.value==""){
alert("请输入用户名");
//将光标移动到文本框中
myform.username.focus();
return false;
}
if(myform.userpwd.value==""){
alert("请输入密码");
myform.userpwd.focus();
return false;
}
if(myform.code.value==""){
alert("请输入验证码");
myform.code.focus();
return false;
}
}
</script>
<style type="text/css">
.code{
width: 80px;
}
.title{
font-size: 20px;
font-weight: bold;
position: relative;
left: 50px;
}
.bd{
background-color:#f0f0f0;
width: 230px;
}
</style>
</head>
<body>
<form action="logincheck.php" method="post" name="myform">
<div>
<div>用户登录</div>
</div>
<div>
<span>用户名:</span>
<span><input type="text" name="username" id="username" placeholder="请输入用户名"></span>
</div>
密码:</span>
</div> 验证码:</span> ="code" placeholder="请输入验证码"></span>
;
<span><input type="hidden" value="hidden"></span>
</form>
</body>
</html>
regcheck.php
<?php
header("content-Type: text/html; charset=Utf-8");
session_start();
//注册处理页面regcheck.php
if (isset($_POST["hidden"])&&$_POST["hidden"]=="hidden") {
$user=trim($_POST["username"]);//使用trim函数移除字符串两侧的空白字符
$pwd=md5(trim($_POST["userpwd"]));
$pwd_confirm=md5(trim($_POST["confirm"]));
$code=$_POST["code"];
if($user==""||$pwd==""||$pwd_confirm==""){
// echo "<script>alert("请确认信息完整性"):history.go(-1);</script>";
}elseif ($code!=$_SESSION["var_code"]) {
// echo "<script>alert("验证码不正确"):history.go(-1);</script>";
}else{
if ($pwd==$pwd_confirm) {
$conn=mysql_connect("localhost","root","a123456");//链接数据库的账号密码
if (mysqli_errno($conn)) {
echo mysqli_errno($conn);
exit;
}
mysqli_select_db($conn,"userdb");//选择数据库
mysqli_set_charset($conn,"utf8");//设定字符集
// $sql="select username from USER where username='$user'";//sql语句
$sql = "SELECT * FROM `user` PROCEDURE ANALYSE()";
// mysql_query(query)
$result=mysqli_query($conn,$sql);//执行SQL语句
$num = mysqli_num_rows($result); //统计执行结果影响的行数
if($num) //如果已经存在该用户
{
echo "<script>alert('用户名已存在'); history.go(-1);</script>";
}
else //不存在当前注册用户名称
{
$ip=ip2long($_SERVER['REMOTE_ADDR']); // 把ip地址转换成整型
$time=time();
$sql_insert = "insert into `user` (`username`,`userpwd`,`createtime`,`createip`) values('" . $user . "','" . $psw ."','".$time."','".$ip."')";
//$sql = "SELECT * FROM `user` PROCEDURE ANALYSE()";
$res_insert = mysqli_query($conn,$sql_insert);
if($res_insert)
{
echo "<script>alert('注册成功!');window.location.href='login.php';</script>";
}
else
{
echo "<script>alert('系统繁忙,请稍候!'); history.go(-1);</script>";
}
}
}
else
{
echo "<script>alert('密码不一致!'); history.go(-1);</script>";
}
}
}
else
{
// echo "<script>alert('提交未成功!');</script>";
echo "<script>alert('weichenggong');</script>";
}
?>
logincheck.php
<?php
header("content-Type: text/html; charset=Utf-8");
session_start();
//登录处理界面 logincheck.php
//判断是否按下提交按钮
if(isset($_POST["hidden"]) && $_POST["hidden"] == "hidden")
{
//将用户名和密码存入变量中,供后续使用
$user = trim($_POST["username"]);//trim()函数移除字符串两侧的空白字符
$psw = md5(trim($_POST["userpwd"]));//密码使用md5()加密一次,存入数据库
$code = $_POST["code"];
if($user == "" || $psw == "")
{
//用户名或者密码其中之一为空,则弹出对话框,确定后返回当前页的上一页
echo "<script>alert('请输入用户名或者密码!'); history.go(-1);</script>";
}else if($code != $_SESSION[' ver_code']){
echo "<script>alert('验证码不正确,请重新输入!'); history.go(-1);</script>";
}
else
{ //确认用户名密码验证码不为空,则连接数据库
$conn = mysqli_connect("localhost","root","a123456");//数据库帐号密码为安装数据库时设置
if(mysqli_errno($conn)){
echo mysqli_errno($conn);
exit;
}
mysqli_select_db($conn,"userdb");
mysqli_set_charset($conn,'utf8');
$sql = "select username,userpwd from user where username = '$user' and userpwd = '$psw'";
//$sql = "SELECT * FROM `user` PROCEDURE ANALYSE()";
$result = mysqli_query($conn,$sql);
$num = mysqli_num_rows($result);
if($num)
{
echo "<script>alert('成功登录'); window.location.href='index.php';</script>";
}
else
{
echo "<script>alert('用户名或密码不正确!');history.go(-1);</script>";
}
}
}
else
{
echo "<script>alert('提交未成功!');</script>";
}
?>
register.php
<!DOCTYPE html>
<html>
<head>
<title>php.cn</title>
<meta charset="utf-8" />
<style>
.box{
width:250px;
height:120px;
background:#f0f0f0;
}
</style>
</head>
<body>
<!-- 注册界面 register.php-->
<div class="box" align="center">
<div>用户注册</div>
<form action="regcheck.php" method="post">
<table>
<tr>
<td align="right">用户名:</td>
<td><input type="text" name="username" maxLength="6"/></td>
</tr>
<tr>
<td align="right">密 码:</td>
<td><input type="password" name="userpwd" maxLength="6"/></td>
</tr>
<tr>
<td align="right">确认密码:</td>
<td><input type="password" name="confirm" maxLength="6"/></td>
</tr>
<tr>
<td colspa="2" align="right"><input type="Submit" name="Submit" value="注册"/></td>
</tr>
</table>
</form>
</div>
</body>
</html>
求大神解决,我觉得再解决不出来,我的头发都要掉光了