PhP登录/注册系统 [英] PhP Login/Register system
问题描述
我找到了有关使用PhP和MySQL创建登录/注册系统的好教程. 该论坛大约有5年历史(去年编辑),但仍然有用.
I found this good tutorial on creating a login/register system using PhP and MySQL. The forum is around 5 years old (edited last year) but it can still be usefull.
登录页面和注册页面似乎都存在问题.
There seems to be an issue with both login and register pages.
<?php
function register_form(){
$date = date('D, M, Y');
echo "<form action='?act=register' method='post'>"
."Username: <input type='text' name='username' size='30'><br>"
."Password: <input type='password' name='password' size='30'><br>"
."Confirm your password: <input type='password' name='password_conf' size='30'><br>"
."Email: <input type='text' name='email' size='30'><br>"
."<input type='hidden' name='date' value='$date'>"
."<input type='submit' value='Register'>"
."</form>";
}
function register(){
$connect = mysql_connect("host", "username", "password");
if(!$connect){
die(mysql_error());
}
$select_db = mysql_select_db("database", $connect);
if(!$select_db){
die(mysql_error());
}
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$pass_conf = $_REQUEST['password_conf'];
$email = $_REQUEST['email'];
$date = $_REQUEST['date'];
if(empty($username)){
die("Please enter your username!<br>");
}
if(empty($password)){
die("Please enter your password!<br>");
}
if(empty($pass_conf)){
die("Please confirm your password!<br>");
}
if(empty($email)){
die("Please enter your email!");
}
$user_check = mysql_query("SELECT username FROM users WHERE username='$username'");
$do_user_check = mysql_num_rows($user_check);
$email_check = mysql_query("SELECT email FROM users WHERE email='$email'");
$do_email_check = mysql_num_rows($email_check);
if($do_user_check > 0){
die("Username is already in use!<br>");
}
if($do_email_check > 0){
die("Email is already in use!");
}
if($password != $pass_conf){
die("Passwords don't match!");
}
$insert = mysql_query("INSERT INTO users (username, password, email) VALUES ('$username', '$password', '$email')");
if(!$insert){
die("There's little problem: ".mysql_error());
}
echo $username.", you are now registered. Thank you!<br><a href=login.php>Login</a> | <a href=index.php>Index</a>";
}
switch($act){
default;
register_form();
break;
case "register";
register();
break;
}
?>
一旦按下注册按钮,页面将不执行任何操作,将删除字段,并且不会在数据库内部添加任何数据或出现错误.
我坚信问题可能是switch($act){
部分,因此我将其删除并使用require
Once pressed the register button the page does nothing, fields are erased and no data is added inside the database or error given.
I tought that the problem might be the switch($act){
part so I removed it and changed the page using a require
require('connect.php');
connect.php在哪里
where connect.php is
<?php
mysql_connect("localhost","host","password");
mysql_select_db("database");
?>
删除了function register_form(){
和echo
部分,将其转换为HTML代码:
Removed the function register_form(){
and echo
part turning it into an HTML code:
<form action='register' method='post'>
Username: <input type='text' name='username' size='30'><br>
Password: <input type='password' name='password' size='30'><br>
Confirm your password: <input type='password' name='password_conf' size='30'><br>
Email: <input type='text' name='email' size='30'><br>
<input type='hidden' name='date' value='$date'>
<input type='submit' name="register" value='Register'>
</form>
而不是用if($register){
代替了if($register){
因此,当按下注册"按钮时,它将运行php代码,但此编辑似乎也不起作用.那么问题是什么呢?如果需要,我可以在域中重新添加此代码
So when the Register button is pressed it runs the php code, but this edit doesn't seem to work either. So what can the problem be? If needed I can re-add this code on my Domain
登录页面有相同的问题,在清空字段旁边按按钮时,什么也没有发生.
The login page has the same issue, nothing happens when the button is pressed beside emptying the fields.
推荐答案
没关系的人,我发现了另一个带有视频演示的教程.奇迹般有效. 我的页面 添加了登录/注册系统.
Nevermind guys I found a different tutorial with video demonstration. Works like a charm. My Page Added the Login/Register system.
教程(如果有人需要).感谢您的答复,我将不胜感激,并将对其+1.
Tutorial if anyone needs it. Thanks for answering tho I appreciate it and will +1 them.
这篇关于PhP登录/注册系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!