Jump to content

my register page doesn't work


Striapper

Recommended Posts

Hi guys, i'm having trouble with my register page.

I don't get any error but when I try to register i get a blank page and just cant figure out where i have gone wrong any help would be would be great

Thanks in advance.

<?php
include "functions.php";
connect();

if(isset($_POST['register'])) {
 $username = protect($_POST['username']);
 $password = protect($_POST['password']);
 $email = protect($_POST['email']);

 if(strlen($username) > 20) {
    echo "Username must be less than 20 characters!";
 }elseif(strlen($email) > 100) {
    echo "Email must be less than 100 characters!";
 }else{
    $stmt = $mysqli->prepare("SELECT username FROM user WHERE username = ? LIMIT 1");
    $stmt->bind_param("s", $username);
    $stmt->execute();
    $result = $stmt->get_result();
    if($result->num_rows == 1) {
        echo "Username already taken!";
    }else{
    $sql = "INSERT INTO user (username, password, email) VALUES(?,?,?)";
    $stmt = $db->prepare($sql);
    $stmt->bind_param("sss", $username, $password, $email);
    $stmt->execute();
    echo "Sucsessfully registered";
    $mysqli -> close();
}
 }
}
?>

 

Edited by Striapper
Link to comment
Share on other sites

If your script is working correctly then there will always be output - except in the case that there was no "register" submitted with the form. So first thing is to check that.

Otherwise you'll have some sort of error. Make sure your php.ini is set up appropriately for a development environment by ensuring it has these two settings:

display_errors = on
error_reporting = -1

(like at the bottom) and then restart PHP/the server/whatever you're using. You should then end up with a not-blank page...

Link to comment
Share on other sites

What I do is add

<?php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

to the top of the file. This lets me see everything. It's the same thing as what requinix suggests, just doing it using code instead.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.