-3

[NOTE-EDIT: THIS QUESTION IS DIFFERENT BECAUSE I AM ASKING WHY THE FORM DATA WILL NOT TRANSFER/INSERT INTO MY SQL DATABASE]

I have a website where you can login/signup and I have created a phpAdmin/mySQL database with a table to save data in. I coded a form in HTML:

<br>
<br>
<text align="center">
<div id="body-context">
<h3>You can't login to accounts yet, but you can create one here!</h3>
<p>You will be able to login to accounts in 2.5 days</p>
<p>
<form action="create-account.php" method="post">
<input type="text" placeholder="Username, 8-16 characters" name="username" pattern=".{8,16}" required>
<br>
<input type="password" placeholder="Password, 9-26 characters" name="password" pattern=".{9,26}" required>
<br>
<input type="text" placeholder="Email Address" name="email" pattern=".{11,}" required>
<br>
<input type="submit" value="Create Account">
</form>
</p>
</div>
</text>

PHP: (this is the create-account.php action page)

<?php

con = mysqli_connect('server-name', 'username', 'password', 'database-name')

 if(!$con)
 {
  echo 'Not Connected to Server';
 }

if(!mysqli_select_db($con, 'database-name'))
{
 echo 'Database Not Selected';
}

$username = $POST['username'];
$password = $POST['password'];
$email = $POST['email'];

$sql = "INSERT INTO Users (username,email,password) VALUES ('$username','$email','$password')";

if(!mysqli_query($con,$sql))
{
 echo 'Not Inserted';
}
else
{
 echo 'Inserted';
}

?>

I tested the code out on my in-progress website, but after I filled out the form and submit it, I went to look at the database and nothing was there. I kept trying but nothing was there. How can I fix this problem (or debug the code if something is wrong with it)?

1 Answers1

-3

All these:

$username = $POST['username'];
$password = $POST['password'];
$email = $POST['email'];

Change to below:

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

or

$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$email = $_REQUEST['email'];
slon
  • 1,002
  • 1
  • 8
  • 12