PHP 注册系统不起作用(phpmyadmin、wampserver) [英] PHP signup system won't work (phpmyadmin, wampserver)

查看:54
本文介绍了PHP 注册系统不起作用(phpmyadmin、wampserver)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 php 注册系统无法连接到我本地托管的 phpmyadmin 数据库,即使我已经检查了拼写错误并且一切似乎都可以正常工作.即使在 PHP 注册脚本中说明了标头,它也不会更改.没有任何东西被传输到我的数据库中(它没有错误).如果有人能告诉我我做错了什么,那就太好了.(P.S.footer.php 和 header.php 正确并包含在表单中)

注册错误处理程序并注册脚本:

 0) {header("位置:../signup.php?signup=usertaken");出口();} 别的 {//哈希密码$hashedPassword = password_hash($password,PASSWORD_DEFAULT);//将用户插入数据库$sql = "插入用户 (user_first, user_last,user_email, user_username, user_password) VALUES ('$first', '$last','$email', '$username' '$hashedPassword');";mysqli_query($conn, $sql);header("位置:../signup.php?signup=success");出口();}}}}} 别的 {header("位置:../signup.php");出口();}

数据库连接:

注册表单(php文件中的html):

</节><?php include_once 'footer.php';?>

如果可以,请帮忙.将不胜感激.谢谢!

解决方案

为 HTML 注册页面的提交按钮命名为提交":

 

更改 PHP 注册页面发布:

$first = mysqli_real_escape_string($conn, $_POST['first']);$last = mysqli_real_escape_string($conn, $_POST['last']);$email = mysqli_real_escape_string($conn, $_POST['email']);$username = mysqli_real_escape_string($conn, $_POST['username']);$password = mysqli_real_escape_string($conn, $_POST['password']);

将 stmt 的空值检查更改为:

if ( (empty($first)) || (empty($last)) or (empty($email)) || (empty($username)) || (empty($password)))

更改输入字符有效性检查,如果 stmt 为:

if ( (!preg_match("/^[a-zA-Z]*$/", $first)) || ((!preg_match("/^[a-zA-Z]*$/", $last)) ) )

My php signup system won't connect to my locally hosted phpmyadmin database even though I've checked through spelling errors and everything seems like it should work. The header wont change even though it's stated in the PHP sign up script. Nothing is being transferred into my database(which has no errors with it). If someone could tell me what I'm doing wrong that would be great. (P.S. footer.php and header.php are correct and included in the form)

Sign up error handlers and sign up script:

<?php

if (isset($_POST['submit'])) {

include_once 'dbh.inc.php';

$first = mysqli_real_escape_string($conn, $_POST)$_POST['first'];
$last = mysqli_real_escape_string($conn, $_POST)$_POST['last'];
$email = mysqli_real_escape_string($conn, $_POST)$_POST['email'];
$username = mysqli_real_escape_string($conn, $_POST)$_POST['username'];
$password = mysqli_real_escape_string($conn, $_POST)$_POST['password'];

//Error handlers
//Check for empty fields
if (empty($first)) || (empty($last)) || (empty($email)) || 
(empty($username)) || (empty($password)) {
    header("Location: ../signup.php?signup=empty");
    exit();
} else {
    //Check is input characters are valid
    if (!preg_match("/^[a-zA-Z]*$/", $first) || (!preg_match("/^[a-zA-
Z]*$/", $last)) {
        header("Location: ../signup.php?signup=invalid");
        exit();
    } else {
        //Check if email is valid
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            header("Location: ../signup.php?signup=empty");
            exit();
        } else {
            $sql = "SELECT * FROM users WHERE user_username='username'";
            $result = mysqli_query($conn, $sql);
            $resultCheck = mysqli_num_rows($result);

            if ($resultCheck > 0) {
                header("Location: ../signup.php?signup=usertaken");
                exit();
            } else {
                //Hashing the password
                $hashedPassword = password_hash($password, 
PASSWORD_DEFAULT);
                //Insert the user into the database
                $sql = "INSERT INTO users (user_first, user_last, 
 user_email, user_username, user_password) VALUES ('$first', '$last', 
'$email', '$username' '$hashedPassword');";
                mysqli_query($conn, $sql);
                header("Location: ../signup.php?signup=success");
                exit();
            }
        }
    }
 }

} else {
header("Location: ../signup.php");
exit();
}

Database connection:

<?php

$dbServername = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbServername = "loginsystem";

$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, 
$dbServername);

Sign up form(html in a php file):

<?php include_once 'header.php';?>

<section class="main-container">
<div class="wrapper">
    <h2>Sign Up</h2>
    <form class="Sign" action="includes/signup.inc.php" method="POST">
        <input type="text" name="first" placeholder="First Name"><br>
        <input type="text" name="last" placeholder="Last Name"><br>
        <input type="email" name="email" placeholder="E-mail"><br>
        <input type="text" name="username" placeholder="Username"><br>
        <input type="password" name="password" placeholder="Password"><br>
        <button type="submit" name="">Sign Up!</button><br>
    </form>
</div>              
</section>  

<?php include_once 'footer.php';?>

Please help if you can. It would be much appreciated. Thanks!

解决方案

Give the name 'submit' to submit button of your HTML Signup Page:

 <button type="submit" name="submit">Sign Up!</button> 

Change PHP Signup Page POST:

$first = mysqli_real_escape_string($conn, $_POST['first']);
$last = mysqli_real_escape_string($conn, $_POST['last']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$username = mysqli_real_escape_string($conn, $_POST['username']);
$password = mysqli_real_escape_string($conn, $_POST['password']);

Change empty values checking of stmt to:

if ( (empty($first)) || (empty($last)) or (empty($email)) || (empty($username)) || (empty($password)) )

Change input characters validity checking if stmt to:

if ( (!preg_match("/^[a-zA-Z]*$/", $first)) || ((!preg_match("/^[a-zA-Z]*$/", $last)) ) )

这篇关于PHP 注册系统不起作用(phpmyadmin、wampserver)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆