Skip to content

Instantly share code, notes, and snippets.

@simplyniceweb
Last active November 26, 2016 16:53
Show Gist options
  • Save simplyniceweb/6ace3b5f5708fa0767f027bf2507dff2 to your computer and use it in GitHub Desktop.
Save simplyniceweb/6ace3b5f5708fa0767f027bf2507dff2 to your computer and use it in GitHub Desktop.
users
<?php
$servername = "localhost";
$database = "exercise";
$username = "root";
$password = "root";
$connection = new PDO ("mysql:host=$servername;dbname=$database;charset=utf8mb4", $username, $password);
/* End of file */
<!DOCTYPE html>
<html>
<head>
<title> Registration Form </title>
</head>
<body>
<form name="registration" method="post" action="submit.php">
<table>
<tr>
<td>Fullname:</td>
<td><input type="text" name="fullname" autofocus /></td>
</tr>
<tr>
<td>Username:</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td><button type="submit">Registration</button></td>
</tr>
</table>
</form>
</body>
</html>
<?php
include("database.php");
function saveThisShit( $userData, $connection ) {
$statement = $connection->prepare("INSERT INTO users(`fullname`, `username`, `password`) VALUES (?, ?, ?)");
$statement->execute(array($userData["fullname"], $userData["username"], $userData["password"]));
echo "User data saved!";
exit;
}
$userData = array(
"fullname" => $_POST['fullname'],
"username" => $_POST['username'],
"password" => $_POST['password']
);
saveThisShit( $userData, $connection );
/* End of file */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment