0

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.

<?php
session_start();
$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>
        <?php
    } else {
        ?>
        <script>alert('error please contact support.');</script>
        <?php
    }
}
?>
Chris Forrence
  • 10,042
  • 11
  • 48
  • 64
j jl
  • 11
  • 6
  • `var_dump($escusername, $escemail, $hpassword, $query)` then see where is the problem. – Felippe Duarte May 19 '16 at 21:18
  • In your `mysqli_query`, what connection are you writing to? – Chris Forrence May 19 '16 at 21:19
  • 1
    ChrisForrence has the solution: `$result = mysqli_query($con, $query);` – Felippe Duarte May 19 '16 at 21:20
  • 1
    `if(isset($_SESSION['user'])!="")` isn't that supposed to be `if(isset($_SESSION['user']))`? – Andreas May 19 '16 at 21:21
  • @FelippeDuarte string(4) "test" string(13) "test@test.com" string(128) "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff" string(211) "INSERT INTO `users` (username, email, password) VALUES('test', 'test@test.com', 'ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff')" – j jl May 19 '16 at 21:22
  • @ChrisForrence hahahaha i feel stupid! thanks. – j jl May 19 '16 at 21:24
  • Go enable proper error reporting, then PHP can tell you about stuff like this itself already. – CBroe May 19 '16 at 21:26

2 Answers2

0
$result = mysqli_query($con, $query);
j jl
  • 11
  • 6
0

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

Felippe Duarte
  • 14,901
  • 2
  • 25
  • 29
  • @FelippeDaurte For some reason it's now only allowing 1 user per table otherwise it won't register and it will show the error output, i'm assuming the error is in my sql file? – j jl May 19 '16 at 21:32
  • Never mind fixed it another silly issue lol – j jl May 19 '16 at 21:34
  • You can get the error with `mysqli_error($con)` after your query. Check this. – Felippe Duarte May 19 '16 at 21:34