php - 在php中创建登录/注册系统但在mysql数据库phpmyadmin中没有显示

标签 php mysql database authentication

所以实际上问题是我需要一个登录/注册系统和我写的东西并且它工作一切正常登录和注册工作除了当我尝试创建帐户时我写下它需要的所有东西并创建它和它说你注册成功了!但是当我去检查数据库时,没有带有 id username pass 等的新数据,但是我连接到数据库或任何东西都没有错误,当我尝试登录时我不能因为没有数据来自数据库中的注册。我还检查了两次数据库名称,我认为它在代码中没有错,或者我在 php 中有点新。

如果有人需要,我可以在 Skype 上添加他,或者您可以查看 teamviewer,如果您愿意,我真的需要这个修复程序!!

数据库图片:http://shrani.si/f/1f/pO/3sIbCuUk/brez-naslova.png还不能直接发图片

数据库服务器

Server: 127.0.0.1 via TCP/IP
Server type: MySQL
Server version: 5.6.14 - MySQL Community Server (GPL)
Protocol version: 10
User: root@localhost
Server charset: UTF-8 Unicode (utf8)

网络服务器

Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.5.6
Database client version: libmysql - mysqlnd 5.0.11-dev - 20120503 
PHP extension: mysqli Documentation

这是我的register.php文件

echo "<h1>Sign Up</h1>";

$submit = @$_POST['submit'];

//form data
$fullname = strip_tags(@$_POST['fullname']);
$username = strip_tags(@$_POST['username']);
$password = strip_tags(@$_POST['password']);
$confirmpassword = strip_tags(@$_POST['confirmpassword']);
$date = date("Y-m-d");

if($submit)
{
//check for existance
    if($fullname&&$username&&$password&&$confirmpassword)
    {
        if($password==$confirmpassword)
        {
            if (strlen($username)>25||strlen($fullname)>25)
            {
                echo "Lenght of username or full name is too long!"; 
            }
            else
            {
                if(strlen($password)>25||strlen($password)<6)
                {
                    echo "Your password must be between 6 and 25 characters long!";
                }
                else
                {
                    //register the user
                    //encrypt password
                    $password = md5($password);
                    $confirmpassword = md5($confirmpassword);
                    //connect to databases
                    $connect = mysql_connect("localhost", "root", "");
                    mysql_select_db("login");

                    $queryreg = mysql_query("INSERT INTO users VALUES   ('','$fullname','$username','$password','$date'");

                    die("You've succsessfully registered! <a href='index2.php'>Click here to return to the login page!</a>");

                }
            }
        }
        else
        {
            echo "Your passwords do not match!";
        }
    }
    else
    {
        echo "Please enter all fields!";
    }
}

?>


<p>
<form action="register.php" method="POST">
    <table>
        <tr>
            <td>
            Full Name: 
            </td>
            <td>
                <input type="text" name="fullname" value="<?php echo $fullname?>">
            </td>
        </tr>
        <tr>
            <td>
            Username: 
            </td>
            <td>
                <input type="text" name="username" value="<?php echo $username ?>">
            </td>
        </tr>
        <tr>
            <td>
            Password: 
            </td>
            <td>
                <input type="password" name="password">
            </td>
        </tr>
        <tr>
            <td>
            Confirm Password: 
            </td>
            <td>
                <input type="password" name="confirmpassword">
            </td>
        </tr>
    </table>
    <p>
        <input type="submit" name="submit" value="Create Account"> 
    </p>
</form>

那是我的 index2.php 我将它命名为 index2.php 因为我已经有 1 个 index.php

<head>
    <title>Login Session</title>
</head>

<body>

    <form method="POST" action="login.php">
        Username: <input type="text" name="username"><br/>
        Password: <input type="password" name="password"><br/>
            <input type="submit" name="submit" value="Log in">
            <a href="register.php">Create An Account</a>
            <a href="index.php">Domov</a>
    </form>


</body>

这是 login.php

session_start();

$username = $_POST['username'];
$password = $_POST['password'];

if ($username&&$password)
{
$connect = mysql_connect("localhost", "root", "") or die("Couldn't connect to host!");
mysql_select_db("login") or die("Couldn't find database!");

$query = mysql_query("SELECT * FROM users WHERE username ='$username'");

$numrows = mysql_num_rows($query);
if ($numrows!=0)
{
    while ($row = mysql_fetch_assoc($query))
    {
        $dbusername = $row['username'];
        $dbpassword = $row['password'];
    }

    if($username==$dbusername&&md5($password)==$dbpassword)
    {

        $_SESSION['username']=$username;
        header("Location: member.php");


    }
    else
    {
        echo "Wrong password!";
    }
}
else
{
    die("That user hasn't been created!");

}   
}

else 
{
    echo "Username and password must be entered!";   
}

和 member.php

session_start();

if ($_SESSION['username'])
    echo "Hello, ".$_SESSION['username']."!<br/><a href='logout.php'>Sign Out";
else 
{
        header("Location: index2.php");
}

最佳答案

我认为您正在尝试插入没有有效主键的记录。使用 null 而不是 '' 作为主键

$queryreg = mysql_query("INSERT INTO users VALUES (null,'$fullname','$username','$password','$date'");

也可以在查询后使用die(mysql_error());查看查询是否有错误

非常重要

您应该使用 md5 来散列密码,它非常脆弱且不安全。使用 bcrypt反而。此外,您不应该使用 mysql_* 函数,因为它们已被弃用,请改用 mysqli

关于php - 在php中创建登录/注册系统但在mysql数据库phpmyadmin中没有显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21650158/

相关文章:

php - 我的 access.log 中出现奇怪的 url "http://www.proxy-listen.de/azenv.php"

PHP按键值降序对数组进行数字排序

php - 如果 MySQL 行输出等于 X 则执行 Y

Python将数组元素插入mysql数据库

php - 使用 PHP 从 MySQL 数据库构建索引表

c# - SQLite 连接未出现在实体数据模型向导中

PHP:如何检查当前是否正在写入文件

javascript - 从匿名用户那里收集什么是好的信息?

java - 为什么我需要在 Hibernate 中进行事务以进行只读操作?

mysql - SQL 查询 - 使用条件连接两个表