0

I have this code on localhost and live hosting but always bool(false) bool(false) on live hosting when I fill up the text area of username and password but it adds up to the database of the hosting but no value in it because its false.

When I run it to my localhost its just fine displaying the results of the username, password and the hash value and adds up to the database.

<?php

include "db.php";
require "lib/password.php";

    if (isset($_POST['submit']))
    {       
                    $username= $_POST['leguser'] ;
                    $password= $_POST['legpass'] ;  
                    $pwhash = password_hash($password, PASSWORD_DEFAULT) ;
                    $username = mysql_real_escape_string($username);
                    $password = mysql_real_escape_string($password);

                    echo var_dump ($username);
                    echo var_dump ($password);
                    echo var_dump ($pwhash);

        $sql = "SELECT * FROM tbl_users WHERE fld_username = '$username'";
        $result = $conn->query($sql);
        if ($result->num_rows == true) { 
                         echo "<script>alert('Username already used!');</script>"; }
                    else
                    {                               
        $q = "INSERT INTO `tbl_users` (`fld_username`,`fld_password`) VALUES ('$username','$pwhash')";
            $result = $conn->query($q);
                if ($result) {
                    echo 'success';
                } else {
                    echo 'failure: ' . mysql_error(); 
                }
                    }            

}

?>

Thank you for the help in advance, I am just a beginner in this field :)

5
  • Normally, you should first reduce the example code so that it contains the bare minimum. As it stands, parts are missing and others are superfluous. Then, format your code, after all you want others to read it. Here though, you should take another route and use PDO instead. It does things like escaping of strings to avoid SQL injection for you, which reduces the amount of code you have to write and where you could make errors. Feb 16, 2015 at 6:57
  • Check the database connection
    – Vidya L
    Feb 16, 2015 at 7:10
  • database connection is fine and its connected both live and localhost. Feb 16, 2015 at 7:11
  • what do you get for doing a var_dump on $_POST instead of your assigned variables?
    – Simon
    Feb 16, 2015 at 7:46
  • i only get Bool(false) = username Bool(false) = password and the hash value (60 chars) and a success echo that notify me if it is inserted to the database or not. Feb 16, 2015 at 8:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.