Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Web MaplebitCMS - Registration does not insert accounts into the database

Newbie Spellweaver
Joined
Aug 17, 2016
Messages
33
Reaction score
6
We are currently using the Maplebit CMS for registration etc, we set it up but accounts do not get inserted, although it did say that it succesfully connected to the database back when i set it up.
I am not sure what i should show to fix this, any help with it? It only seems to have problems with inserting the data into the databases account table.

Please note that all the database related things were correct.

the register.php
Code:
<?php if(basename($_SERVER["PHP_SELF"]) == "register.php") {
    die("403 - Access Forbidden");
}
if(isset($_SESSION['id'])) {
    echo "<meta http-equiv=refresh content=\"0; url=?base=ucp\">";
}
else {
echo "<h2 class=\"text-left\">Registration</h2><hr/>";
if (!isset($_POST['submit'])) {
?>
    <form action="?base=main&page=register" method="POST">
    <div class="form-group">
        <label for="inputUser">Username</label>
        <input type="text" name="musername" maxlength="12" class="form-control" id="inputUser" autocomplete="off" placeholder="Username" required>
    </div>
    <div class="form-group">
        <label for="inputPass">Password</label>
        <input type="password" name="mpass" maxlength="12" class="form-control" id="inputPass" autocomplete="off" placeholder="Password" required>
    </div>
    <div class="form-group">
        <label for="inputConfirm">Confirm Password</label>
        <input type="password" name="mpwcheck" maxlength="12" class="form-control" id="inputConfirm" autocomplete="off" placeholder="Confirm Password" required>
    </div>
    <div class="form-group">
        <label for="inputEmail">Email</label>
        <input type="email" name="memail" class="form-control" id="inputEmail" autocomplete="off" placeholder="Email" required>
    </div>
    <b>reCAPTCHA</b>
    <?php
        require_once('assets/config/recaptchalib.php');
        $error = null;
        $publickey = "6LemqAwAAAAAAF4dIpSjTB3GJt1ax0MRQ9FvOX_T";
        $privatekey = "6LemqAwAAAAAAO69RT3j9M1eHPX_ahhmC6Gakuwb";
        echo recaptcha_get_html($publickey, $error);
    ?>
        <br/>
        <input type="submit" class="btn btn-primary" name="submit" value="Register »"> 
    </form>
<?php
}
else {
    if (!isset($_POST["musername"]) ||
        !isset($_POST["mpass"]) ||
        !isset($_POST["mpwcheck"]) ||
        !isset($_POST["memail"]) ||
        !isset($_POST["recaptcha_response_field"])) {
        die ("<div class=\"alert alert-error\">Please fill in the correct ReCAPTCHA code!<br/><a onclick=\"goBack()\">« Go Back</a></div>");
    }
    
    $username = $mysqli->real_escape_string($_POST["musername"]); # Get Username
    $password = $_POST["mpass"]; # Get Password
    $confirm_password = $_POST["mpwcheck"]; # Get Confirm Password
    $email = $mysqli->real_escape_string($_POST["memail"]);
    $birth = "1990-01-01";
    $ip = getRealIpAddr();
    
    $continue = false;
    
    require_once('assets/config/recaptchalib.php');


    $publickey = "6LemqAwAAAAAAF4dIpSjTB3GJt1ax0MRQ9FvOX_T";
    $privatekey = "6LemqAwAAAAAAO69RT3j9M1eHPX_ahhmC6Gakuwb";
    
    $resp = null;


    if ($_POST["recaptcha_response_field"]) {
        $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
        if ($resp->is_valid) {
            $continue = true;
        }
    }
    $continue = true;
    if (!$continue) {
        echo ("<div class=\"alert alert-danger\">Please fill in the correct ReCAPTCHA code!<br/><a href=\"?base=main&page=register\">« Go Back</a></div>");
    }
    else {
        $select_user_result = $mysqli->query("SELECT COUNT(*) FROM accounts WHERE name='".$username."' OR email='".$email."'");
        if ($select_user_result->fetch_row()[0]) {
            echo ("<div class=\"alert alert-danger\">This username or email is already used!<br/><a href=\"?base=main&page=register\">« Go Back</a></div>");
        }
        else if ($password != $confirm_password) {
            echo ("<div class=\"alert alert-danger\">Passwords didn't match!<br/><a href=\"?base=main&page=register\">« Go Back</a></div>");
        }
        else if (strlen($password) < 6 || strlen($password) > 12) {
            echo ("<div class=\"alert alert-danger\">Your password must be between 6-12 characters<br/><a href=\"?base=main&page=register\">« Go Back</a></div>");
        }
        else if (strlen($username) < 4 || strlen($username) > 12) {
            echo ("<div class=\"alert alert-danger\">Your username must be between 4-12 characters<br/><a href=\"?base=main&page=register\">« Go Back</a></div>");
        }
        else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            echo ("<div class=\"alert alert-danger\">Please fill in a valid email address.<br/><a href=\"?base=main&page=register\">« Go Back</a></div>");
        }
        else {
            //All data is ok
            $password = sha1($password);
            $insert_user_query = "INSERT INTO accounts (`name`, `password`, `ip`, `email`, `birthday`) VALUES ('".$username."', '".$password."', '".$ip."', '".$email."', '".$birth."')";
            $mysqli->query($insert_user_query);
            echo "<div class=\"alert alert-success\"><b>Success!</b> Please login, and head to the downloads page to get started!</div>";
        }
    }
}
}

and the columns for accounts are: id, name, password, salt, pin, pic, loggedin, lastlogin, createdat, birthday, banned, banreason, gm, macs, nxCredit, maplePoint, nxPrepaid, characterslots, tempban, greason, tos, sitelogged, webadmin, nick, mute, email, ip, rewardpoints, hwid and votepoints

I did get this error code

Code:
 17-Aug-2016 21:14:10 UTC] PHP Fatal error:  Call to a member function fetch_row() on boolean in C:\wamp\www\sources\public\register.php on line 79[17-Aug-2016 21:14:10 UTC] PHP Stack trace:[17-Aug-2016 21:14:10 UTC] PHP   1. {main}() C:\wamp\www\index.php:0[17-Aug-2016 21:14:10 UTC] PHP   2. include() C:\wamp\www\index.php:30[17-Aug-2016 21:14:10 UTC] PHP   3. include() C:\wamp\www\sources\public\main.php:50
 
Last edited:
Infraction Baɴɴed
Loyal Member
Joined
Apr 9, 2008
Messages
1,416
Reaction score
169
change
Code:
if ($select_user_result->fetch_row()[0]) {
	echo ("<div class=\"alert alert-danger\">This username or email is already used!<br/><a href=\"?base=main&page=register\">« Go Back</a></div>");
}
to
Code:
if ($select_user_result->fetch_row()[0] > 0) {
	echo ("<div class=\"alert alert-danger\">This username or email is already used!<br/><a href=\"?base=main&page=register\">« Go Back</a></div>");
}


it was a invalid boolean check.
 
Upvote 0
Back
Top