Mikee
Active Member
- Jul 8, 2017
- 162
- 102
Since devbest's community has a lot of php programmers I'm interested in getting criticized; also this subforum is lacking activity imo.
I'm Learning how to pull POST Data for a register page and send it to a db. Let me know how I did.
Note, I've never developed for the web before.
I'm Learning how to pull POST Data for a register page and send it to a db. Let me know how I did.
Note, I've never developed for the web before.
PHP:
<?php
require_once("Template/index.php");
require("Engine/DBConnect");
$Database = DBConnect::EstablishConnect();
if (isset($_REQUEST["submit"]) && $_POST['username'] != null && $_POST['password'] == $_POST['confirm_password']){
$Username = $_POST['username'];
$EncryptedPassword = password_hash($_POST['password'], PASSWORD_BCRYPT);
$NewUser = $Database->prepare("INSERT INTO users (username, password) VALUES (?, ?)");
$NewUser->execute([$Username,$EncryptedPassword]);
}else if(!isset($_REQUEST["submit"])){
return;
}else{
echo "Some fields are missing values";
}
Code:
<?php
class DBConnect{
function __construct(){
}
public static function EstablishConnect(){
$PDO = new PDO("mysql:host=localhost;dbname=first_site", "root", "password");
return $PDO;
}
}
?>
Code:
<HTML>
<head>
<title>Mike's Website</title>
</head>
<body>
<form name = "form" method = "POST">
<center>
Username:</br>
<input type = "text" name="username"></br>
Password:</br>
<input type = "text" name="password"></br>
Confirm Password:</br>
<input type = "text" name="confirm_password"></br>
<button type = "submit" name = "submit">Register</button>
</center>
</form>
</body>
</HTML>