dtueufe82643 2016-12-14 16:31
浏览 30

PHP和MYSQL代码在localhost中不起作用

Good day. I would like to ask what's wrong with my codes. These already worked in a website that we made with my mate but as I run "register.php", I cannot insert data to my table named 'accounts'. Thanks in advance. Here are the codes:

connect.php

<?php 
//Callback function for connecting the website to the accounts database.
$connect = mysqli_connect('localhost', 'root', '');
if (!$connect){
    die("Database Connection Failed" . mysqli_error($connect));
}
//Selects the database
$select_database = mysqli_select_db($connect, 'users');
if (!$select_database){
    die("Database Selection Failed" . mysqli_error($connect));
}

register.php

<?php
session_start();
require('connect.php');
//If the values are posted, insert them into the database.
if (isset($_POST['username']) && isset($_POST['pass'])){
    $username = $_POST['username'];
    $email = $_POST['email'];
    $password = $_POST['pass'];
    $passwordauth = $_POST['passwordauth'];
    if($password == $passwordauth){
    $password = hash ( 'sha256' , $password ); // hash function creates
        an encrypted code form the $password for security considerations
    $query = "INSERT INTO accounts (username, password, email) VALUES
           ('$username', '$password', '$email')";
    $result = mysqli_query($connect, $query);
    if($result){
        $msg = "User Created Successfully.";
    }
    else{
        $msg ="User Registration Failed";
    }
    }
    else
    {
    $msg ="Password does not match.";
    }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器