0

NEED HELP SQL DATABASE PHP FORM!!!!

Can somebody tell me whats wrong with this code. I defined this file as database_connection.php <?php $connection = mysqli_connect("localhost", "root", "", "loginpage"); if(!$connection) { echo "Something went wrong please try again later"; } ?> I defined this one as form.php <?php include "database_connection.php"; $username = $_POST["username"]; $password = $_POST["password"]; $sql = "INSERT INTO users (username, password) VALUES('$username', '$password')"; if(!$sql) { echo "There was an error creating your account"; } if($sql) { header("Location: login.html"); } ?> I defined this one as login.php <?php include "database_connection.php"; $username = $_POST["username"]; $password = $_POST["password"]; $sql = "SELECT * FROM users WHERE username='$username' AND password='$password'"; $result = $connection->query($sql); if(!$row = $result->fetch_assoc()) { echo "Your username or password is incorrect?"; } else { echo "Welcome back"; } ?> so I signup making the username Jerome and the password Jerome then I go to login and I put the username as Jerome and the password as Jerome but it always returns "Your username or password is incorrect" I don't know what I did wrong. Somebody help pleaase

15th Apr 2018, 8:57 PM
Someone Else
Someone Else - avatar
4 Antworten
+ 6
I'm a beginner in php so I might be wrong. I think in your form.php you need to pass '$sql' to 'mysqli_query()', atleast that's what I was doing in my project.
15th Apr 2018, 9:21 PM
Rusty.Metal
0
Salvador Jaime how would I do that and I how would I know if they match
15th Apr 2018, 9:27 PM
Someone Else
Someone Else - avatar
0
Salvador Jaime can you please explain that code to me I am very new to php
15th Apr 2018, 9:44 PM
Someone Else
Someone Else - avatar
0
Salvador Jaime it still wont work. Why wont it work
15th Apr 2018, 10:22 PM
Someone Else
Someone Else - avatar