再会!
我一直在网上寻找各种解决方案,但我没有通过一个解决我的问题
基本上我一直在制作一个具有注册功能的登录系统,一切都运行良好,除了当我尝试注册时,它没有进入我制作的数据库。然后我尝试将值插入到我的表中,并尝试登录,但它所做的只是登录,即使我输入了错误的密码。
这是数据库:
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| studID | int(11) | NO | PRI | NULL | auto_increment |
| fname | varchar(30) | NO | | NULL | |
| lname | varchar(30) | NO | | NULL | |
| address | varchar(80) | NO | | NULL | |
| username | varchar(20) | NO | | NULL | |
| password | varchar(20) | NO | | NULL | |
+----------+-------------+------+-----+---------+----------------+
索引.html
<html>
<head>
<title>Welcome!</title>
<style>
</head>
<body>
<form name="form1" method="post" action="login.php">
<div align="center">
<p><img src="images/welcome.jpg" /></p>
<table id="title">
<tr>
<td>Username:</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Log In" /></td>
</tr>
</table>
<p>New here? <a href="signup.php">Register!</a></p>
</div>
</form>
</body>
</html>
登录.php
<?php
include("db.php");
session_start();
$username=($_POST['username']);
$password=($_POST['password']);
$result=mysql_query("SELECT count(*) FROM student WHERE username='$username' and password='$password'");
$count=mysql_fetch_array($result);
if($count==0){
session_register("username");
session_register("password");
header("location:success.php");
} else {
echo 'Wrong Username or Password! Return to <a href="index.html">login</a>';
}
?>
和 db.php
<?php
$conn = mysql_connect('localhost', 'root', 'ella');
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("studrecord", $conn);
?>
signup.php(很长,会删掉一些不必要的部分)
<html>
<head>
<title>Register</title>
</head>
<body>
<form action="index.html">
<table id="title">
<tr>
<td>First Name:</td>
<td><input type="text" name="fname" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="lname" /></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address" /></td>
</tr>
<tr>
<td>Username:</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Sign Up" /></td>
</tr>
</table>
</div>
</form>
<?php
if (isset($_POST['submit']))
{
include 'db.php';
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$address=$_POST['address'];
$username=$_POST['username'];
$password=$_POST['password'];
mysql_query("INSERT INTO student(fname,lname,address,username,password)
VALUES ('$fname','$lname','$address','$username','$password')");
}
?>
</...
先感谢您!