Registration script

Whenever this script is ran the page goes blank, can anyone explain why?

[code]<?php
require ‘config.php’;
require ‘header.php’;

$username = $_POST[‘username’];
$pass1 = $_POST[‘pass1’];
$pass2 = $_POST[‘pass2’];
$email = $_POST[‘email’];

$ucheck = “SELECT username FROM users where username = ‘$username’”;
$result1 = mysqli_query($conn, $ucheck);

if($username == “”) {
echo “Please enter a username”;
}elseif (mysqli_num_rows($result1) != 0) {
$row1 = mysqli_fetch_array($result1, MYSQLI_ASSOC);
return array(true, row);
}
else {
$iuser = “INSERT INTO users (username) VALUES ($username)”;
mysqli_query($conn, $iuser);
}

require ‘footer.php’;[/code]

Well, you can’t do it this way. Let’s recap what your code does:

It gets all of the posted data from your form.
It does NOT validate them, so any beginner hacker can delete your database.
THEN, it runs a query even though the WHERE section may be blank.
THEN, it checks for the data for the WHERE section.

You need to change it so it runs the query only if the input username is valid. So, move the query lines 10-11 into the area of line
17 so that the query only runs if the username is valid. You also need to add quotes to the text data when you insert a new
username. If the second section finds a valid username, it “returns” an array of data, but, it never displays it at any point.
And, lastly, if all goes well, the code does not indicate if it worked. So, if all is good, nothing is displayed!
You might want to turn on all error reporting and then you would see if there are actually errors that are being hidden.

Hope that helps… (So, is this for a class project?)

I’ll Attempt to do what you said. And no, I’m learning php on my own, and am currently trying to create a game

Well, read what I wrote and give it a try. Once you get stuck ask your questions and we can help.

I think the biggest error is where you “RETURN” data but do not display it. But, we can help.

Sponsor our Newsletter | Privacy Policy | Terms of Service