Created
April 3, 2019 10:33
-
-
Save ButlerFuqua/e1b0dbf31259d1c7f646bfe2a17ee66c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$link = mysqli_connect("HOST", "USERNAME", "PASSWORD", "DATABASENAME"); | |
if(mysqli_connect_error()){ | |
die("There was an error connecting to the database."); | |
} | |
if($_POST){ | |
$name = $_POST["name"]; | |
$email = $_POST["email"]; | |
$password = $_POST["password"]; | |
$error = ''; | |
if($name == '' OR $email == '' OR $password == ''){ | |
$error = "Please correctly fill out the form. There was an error."; | |
echo $error; | |
} | |
if($error == ''){ | |
$query = "SELECT `email` FROM users WHERE email = '".mysqli_real_escape_string($link, $_POST['email'])."'"; | |
$result = mysqli_query($link, $query); | |
if(mysqli_num_rows($result) > 0){ | |
echo "already taken"; | |
}else{ | |
$query = "INSERT INTO `users` (`name`, `email`, `password`) VALUES ('".mysqli_real_escape_string($link, $name)."', '".mysqli_real_escape_string($link, $email)."', '".mysqli_real_escape_string($link, $password)."')"; | |
if(mysqli_query($link, $query)){ | |
echo 'Check Database'; | |
}else{ | |
echo 'did not work'; | |
} | |
} | |
} | |
} | |
?> | |
<!-- | |
Ask for email and password | |
Check that the email and password have been entered | |
Check that the email address is not already registered | |
Sign the user up! | |
--> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>MySQL Database</title> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> | |
</head> | |
<body> | |
<div class="container mt-4"> | |
<h4>Enter my database!</h4> | |
<hr> | |
<form action="index.php" method="post"> | |
<div class="form-group"> | |
<label for="name">Name</label> | |
<input name="name" type="name" class="form-control" id="name" aria-describedby="nameHelp" placeholder="Enter name"> | |
</div> | |
<div class="form-group"> | |
<label for="email">Email address</label> | |
<input name="email" type="email" class="form-control" id="email" aria-describedby="emailHelp" placeholder="Enter email"> | |
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small> | |
</div> | |
<div class="form-group"> | |
<label for="password">Password</label> | |
<input name="password" type="password" class="form-control" id="password" placeholder="Password"> | |
</div> | |
<button type="submit" class="btn btn-primary">Submit</button> | |
</form> | |
</div> | |
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script> | |
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment