检查帐户是否存在

时间:2017-05-26 16:28:02

标签: php mysql

我的代码

<?php
session_start();
require './SIGNUP/connects1010101.php';
require './LOGIN/connects1010101.php';
$srausername = $_SESSION['SRAUSERNAME'];
$srapassword = $_SESSION["SRAPASSWORD"];
if ($srausername && $srapassword) {
    $data0 = mysqli_query($con, "SELECT * FROM `INFO` WHERE `USERNAME` = '$srausername' AND `PASSWORD` = '$srapassword'");
    $data1 = mysqli_fetch_array($data0);
}
?>

我是PHP的初学者。我的问题是我在mysql中进行帐户注册但是如何检查帐户是否存在?

2 个答案:

答案 0 :(得分:1)

请更改您的代码,

<?php
session_start();
require './SIGNUP/connects1010101.php';
require './LOGIN/connects1010101.php';
$srausername = $_SESSION['SRAUSERNAME'];
$srapassword = $_SESSION["SRAPASSWORD"];
if ($srausername && $srapassword) {
    $data0 = mysqli_query($con, "SELECT * FROM `INFO` WHERE `USERNAME` = '$srausername' AND `PASSWORD` = '$srapassword'");
    //$data1 = mysqli_fetch_array($data0);

    if (mysqli_num_rows($data0) > 0) {
        // Account already exists
    }else {
        // No account exists and you can save the details here
    }
}
?>

答案 1 :(得分:0)

试试这段代码:

   <?php
    session_start();
    require './SIGNUP/connects1010101.php';
    require './LOGIN/connects1010101.php';
    $srausername = $_SESSION['SRAUSERNAME'];
    $srapassword = $_SESSION["SRAPASSWORD"];



    if ($srausername != '' && $srapassword != '') {
        $data0 = mysqli_query($con, "SELECT * FROM `INFO` WHERE `USERNAME` = '$srausername' AND `PASSWORD` = '$srapassword'");
        if(mysqli_num_rows($data0) > 0){
            // new entry
            $sql = mysqli_query($con, "INSERT INTO `INFO` (`USERNAME`,  `PASSWORD`) VALUES ('$srausername', '$srapassword') ");
            if($sql == true){
                echo 'Account has been registered';
                exit();
            }
        }else{
            // account exists
            echo 'Can not register. Account already exists';
            exit();
        }
    }else{
        echo 'Fields should not be empty!';
        exit();
    }
?>