I have a simple website hosted on 000webhost that consists of index.html and register.php. I now have a functional registration system that allows users to input information, and have the database query the info.
On 000webhost, within public_html I have: php: register.php , .htaccess , index.html
index.html simply contains a button that links to the register page, and register.php contains:
<?php
session_start();
if (isset($_POST['register_btn'])){
if ($_POST['email1'] != $_POST['email2']){
exit("Emails did not match.");
}
//connect to database
$connect = mysqli_connect("localhost", "someUser", "somepassword", "somedb");
if(mysqli_connect_error()){
echo mysqli_connect_error();
exit();
}
//write the paramaterized query
$query = "INSERT INTO test_table(username, email) VALUES(?, ?)";
//prepare the statement
$stmt = mysqli_prepare($connect, $query);
if ($stmt){
//bind
mysqli_stmt_bind_param($stmt, 'ss', $_POST['username'], $_POST['email']);
//execute the query
mysqli_stmt_execute($stmt);
} else{
echo "Error creating statement object";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Register</title>
</head>
<body>
<div class="header">
<h1>Register</h1>
</div>
<form method="post" action="register.php">
<table>
<tr>
<td>Username:</td>
<td><input type="text" name="username" class="textInput"></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email1" class="textInput"></td>
</tr>
<tr>
<td>Re-enter Email:</td>
<td><input type="text" name="email2" class="textInput"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="register_btn" value="Register"></td>
</tr>
</table>
</form>
</body>
</html>
EDIT Changed the focus of the question from proper password registration to simple data entry.