-2

i've been trying to make a login system on my website with a signup button but nothing returns to the database aka its empty, here's the code

<?php

include 'dbh.php', 'connect.php';

$usernames=$_POST['usernames'];
$passwords=$_POST['passwords'];
$repassword=$_POST['repassword'];
$email=$_POST['email'];


$taken="false";
$database="database1";

//Main if Statement
if($usernames&&$passwords&&$email&&$repassword){

//connect to database
    $con = mysqli_connect('localhost', $username, $password) or die("Unable to log into database");
    @mysql_select_db($database1, $con) or die("Unable to connect");

mysql_query("INSERT INTO `users` VALUES('', '$usernames', '$passwords', '$email', '$repassword')") or die ("Strange error");


echo "Account created";

mysql_close($con);

// header("location: index.php");

} else {
    echo"You need to have Username, Password and Email!";

}


?>

i have tried to signup for testing but nothing returns to the database?

here's the html script

<!DOCTYPE html>
<html lang="en">
<head>
    <link href="animate.css" rel="stylesheet">
    <title>Twist - Shortie Lovers!</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Bootstrap CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js" </script>
</head>

<body>
    <div class="navbar navbar-inverse navbar-static-top">
        <div class="container">
            <a href="#" class="navbar-brand animated tada">Twist</a>
            <button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <div class="collapse navbar-collapse navHeaderCollapse">
                <ul class="nav navbar-nav navbar-right">
                    <li class="active"><a href="#">Home</a></li>
                    <li><a href="#">New</a></li>
                    <li class="dropdown">

                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Hot <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Test</a></li>
                        </ul>

                </li>
                <li><a href="#">Upload</a></li>
                <li><a href="#signup" data-toggle="modal">Sign up</a></li>
                <li><a href="#login" data-toggle="modal">Login</a></li>
            </ul>
        </div>
    </div>
</div>

<div class="container">
    <div class="jumbotron text-center">
        <h1>You can do it!</h1>
        <p>How? simple... Make your own movie, get rated by other users and movie makers and WIN!</p>
        <a class="btn btn-info">Read More...</a>
    </div>
</div>
<div class="container text-center">
    <h3>Browse popular Posts or <a href="#login" data-toggle="modal">Login</a></h3>
</div>
<div class="navbar navbar-inverse navbar-fixed-bottom">
    <div class="container">
        <p class="navbar-text pull-left">Copyright &copy; 2016 Twist</p>
        <a href="#" class="navbar-btn btn-danger btn pull-right">Contribute</a>
    </div>
</div>


<!--For signup-->
<div class="modal fade" id="signup" role="dialog" action="create.php" method="POST">
    <div class="modal-dialog">
        <div class="modal-content">
            <form class="form-horizontal" >
                <div class="modal-header">
                    <h4>Signup</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="signup-username" class="col-lg-2 control-label">Username:</label>
                        <div class="col-lg-10">
                            <input type="text" name="usernames" class="form-control" id="signup-username" placeholder="Username" required>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="signup-password" class="col-lg-2 control-label">Password:</label>
                        <div class="col-lg-10">
                            <input type="password" name="passwords" class="form-control" id="signup-password" placeholder="Password" required>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="signup-repassword" class="col-lg-2 control-label">Again:</label>
                        <div class="col-lg-10">
                            <input type="password" name="repassword" class="form-control" id="signup-repassword" placeholder="Retype Password" required>
                            <!--<script>
                                $('form').on('submit1',function(){
                                    if($('#signup-password').val()!=$('#signup-repassword').val()){
                                        alert('Password does not match!');
                                        return false;
                                    }
                                        return true;
                                    });
                            </script>-->
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="signup-email" class="col-lg-2 control-label">Email:</label>
                        <div class="col-lg-10">
                            <input type="text" name="email" class="form-control" id="signup-email" placeholder="Email" required>
                        </div>
                    </div>

                </div>
                  <!--<div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <div class="checkbox">
                            <label>
                                <input type="checkbox"> Remember me
                            </label>
                        </div>
                    </div>
                  </div>-->
                <div class="modal-footer">
                    <a class="btn btn-primary" data-dismiss="modal">Close</a>
                    <button class="btn btn-primary" type="submit1">Sign Up</button>
                </div>
            </form>
        </div>
    </div>
</div>


<!--Login -->
<div class="modal fade" id="login" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <form class="form-horizontal" action="">
                <div class="modal-header">
                    <h4>Login</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="login-username" class="col-lg-2 control-label">Username:</label>
                        <div class="col-lg-10">
                            <input type="text" class="form-control" id="login-username" placeholder="Username" required>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="login-password" class="col-lg-2 control-label">Password:</label>
                        <div class="col-lg-10">
                            <input type="password" class="form-control" id="login-password" placeholder="Password" required>
                        </div>
                    </div>
                </div>
                  <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <div class="checkbox">
                            <label>
                                <input type="checkbox"> Remember me
                            </label>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <a class="btn btn-primary" data-dismiss="modal">Close</a>
                    <button class="btn btn-primary" type="submit">Log In</button>
                </div>
            </form>
        </div>
    </div>
</div>


    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
  • What is the first `'',` for in the insert statement? – Blinkydamo Nov 15 '16 at 12:47
  • Also try `INSERT INTO `users` ( 'username', 'password', 'email', 'repassword ) VALUES('', '$username', '$password', '$email', '$repassword')"` - You know this is bad right, I mean you are silencingthe errors so I presume you do. - http://www.w3schools.com/php/php_mysql_insert.asp – Blinkydamo Nov 15 '16 at 12:48
  • 1
    your database username,password variables and user username and password variables are same..please change that – Azeez Kallayi Nov 15 '16 at 12:50
  • more details please... thank you – Christepher Arakelian Nov 15 '16 at 12:51
  • 1
    More details, ok, you are using the same password and username to access your database as you are trying to insert into your database. You are inserting plain test passwords and using mysql which is unsafe and no longer used. You are open to sql attacks and really should stop and read about PDO and password_hash() before going any further – Blinkydamo Nov 15 '16 at 12:53
  • For one thing, you're outputting before header and error reporting would have told you about it and you're not checking for errors at all. The html form is missing from this also, as is db schema and example values. – Funk Forty Niner Nov 15 '16 at 13:15
  • 2
    ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Nov 15 '16 at 13:25
  • 2
    **Never store plain text passwords!** Please use ***PHP's [built-in functions](http://jayblanchard.net/proper_password_hashing_with_PHP.html)*** to handle password security. If you're using a PHP version less than 5.5 you can use the `password_hash()` [compatibility pack](https://github.com/ircmaxell/password_compat). Make sure you ***[don't escape passwords](http://stackoverflow.com/q/36628418/1011527)*** or use any other cleansing mechanism on them before hashing. Doing so *changes* the password and causes unnecessary additional coding. – Jay Blanchard Nov 15 '16 at 13:25
  • 2
    [Little Bobby](http://bobby-tables.com/) says ***[your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)***. Even [escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) is not safe! ***SQL Injection!*** *It's not just for breakfast any more!* – Jay Blanchard Nov 15 '16 at 13:26
  • 1
    From @tadman: WARNING: Writing your own access control layer is not easy and there are many opportunities to get it severely wrong. Please, do not write your own authentication system when any modern development framework like Laravel comes with a robust authentication system built-in. – Jay Blanchard Nov 15 '16 at 13:26
  • 1
    Have you checked your error logs? You're currently suppressing them with `@` Add error reporting to the top of your file(s) right after your opening ` – Jay Blanchard Nov 15 '16 at 13:26

1 Answers1

0

Your query is probably not working because you override your username and password, so you probably can't login:

$username=$_POST['username'];
$password=$_POST['password'];
$repassword=$_POST['repassword'];
$email=$_POST['email'];


$taken="false";
$database="database1";
$password=""; //This one is already set!!!
$username="root"; //This one is already set!!!

EDIT:

Try adding something like this, to make sure your query is right:

$result = mysql_query('YOUR QUERY');
if (!$result) {
    die('Invalid query: ' . mysql_error());
}
Matheno
  • 4,112
  • 6
  • 36
  • 53