j jl j jl - 2 years ago 65
PHP Question

Issue with my registration handling script

My script is returning the 'error please contact support' output, and I honestly can't find the issue wrong with it so i'm hoping a new set of eyes will be able to spot this. I'm sure it's just a tiny idiotic mistake. Thanks.

$con = mysqli_connect('localhost', 'root', '', 'test');
if (isset($_SESSION['user']) != "") {
header("Location: index.php");

if (isset($_POST['btn-signup'])) {
$escusername = mysqli_real_escape_string($con, $_POST['username']);
$escemail = mysqli_real_escape_string($con, $_POST['email']);
$hpassword = hash('sha512', $_POST['password']);

$query = "INSERT INTO `users` (username, email, password) VALUES('$escusername', '$escemail', '$hpassword')";
$result = mysqli_query($query);
if ($result) {

<script>alert('your account has now been registered.');</script>
} else {
<script>alert('error please contact support.');</script>

Answer Source

@ChrisForrence has the solution: $result = mysqli_query($con, $query);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download