I'm trying to insert a username, password and email into a mysql database. The database works fine, as I can pull data out from it and use on the login page, but I can't seem to create new rows and insert data. The sql database is built up like this:
Table: peter
Primary Key: user_id - Int(5), Not Null, Auto Increment
Attributes:
username - VarChar(35), Not Null
password - VarChar(35), Not Null
email - VarChar(35), Not Null
This is my code
<?php
include("config.php");
if($_SERVER["REQUEST_METHOD"] == "POST") {
$myusername = mysqli_real_escape_string($db,$_POST['username']);
$mypassword = mysqli_real_escape_string($db,$_POST['password']);
$myemail = mysqli_real_escape_string($db,$_POST['email']);
$tbl_name = "peter";
$sql = "INSERT INTO $tbl_name (`username`, `password`, `email`) VALUES ($username, $password, $email)";
header("location: login.php");
}
?>
<html>
<body>
<form action = "" method = "post">
<label>UserName: </label><input type = "text" name = "username" class = "box" required/><br /><br />
<label>Password: </label><input type = "password" name = "password" class = "box" required/><br/><br />
<label>Email: </label><input type = "email" name = "email" class = "box" required/><br/><br />
<input type = "submit" value = " Submit "/><br />
</form>
</body>
</html>
I've tried a lot of fixes, including from other Q&A threads, but none of them have worked. So I hope someone else sees the problem.
Edit: This is the config.php file:
<?php
define('DB_SERVER', 'xxx');
define('DB_USERNAME', 'xxx');
define('DB_PASSWORD', 'xxx');
define('DB_DATABASE', 'xxx');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>