just give code for Mysql user table and register.html
and //finish the code here
Perform these tasks first:
(a) Create a table in your MySQL database called users that has two
varchar(255) fields called
username and password, and an auto_increment int field called id.
Give the username field the
UNIQUE attribute.
(b) Create an html input form called register.html that has two
fields to input username and password.
The id field is auto increment, so it will not have to be input.
The POST action of this form should call
register.php.
I have shown a version of register.php below.
<!DOCTYPE html>
<html>
<head>
<title>Register</title>
<body>
<?php
require_once "config.php";
echo "<p>";
echo "<strong>Connected
successfully</strong><br>";
echo "</p>";
// Processing form data when form is submitted
if($_SERVER['REQUEST_METHOD'] == 'POST'){
// Get submitted values
$user = trim($_POST['username']);
$passwd = trim($_POST['passwd']);
//Create a prepared statement
$sql ="insert into users(username, password) values (?,?)"
;
$stmt = mysqli_prepare($link, $sql);
// Bind variables to the prepared statement as
parameters
mysqli_stmt_bind_param($stmt, "ss",
$param_username,
$param_passwd);
//Set variables
$param_username=$user;
$param_passwd=$passwd;
mysqli_stmt_execute($stmt);
$rows_inserted= mysqli_stmt_affected_rows($stmt);
echo "Inserted ".$rows_inserted." rows";
}
?>
</body>
</html
2. Create a homepage called welcome.html, it will display a
welcome message as below.
You can use the following html code:
<!DOCTYPE html>
<html>
<body>
<h1>Welcome!</h1>
<h2>If you haven't registered, please click register.
</h2>
<p><a href="register.html">Register
here!</a></p>
<h2>If you've registered, please log in. </h2>
<p><a href="login.html">Login
here!</a></p>
</body>
</html>
3. Make sure have a register.html in the same folder. If not,
please finish the in-class
register system first.
4. Create an login.php file and copy and paste the following php
code. Save it in the same
folder.
<!DOCTYPE html>
<html>
<body>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST"){
/** Get submitted username and password */
$user = trim($_POST["username"]);
$password = trim($_POST["password"]);
/** Pass connection information through a config file
*/
require_once "config.php";
/** if connection fails, an error message will be sent, and
as specified in the config file
*/
/** if connection succeeds, display a message */
echo "<p>";
echo "<strong>Connected
successfully</strong><br>";
echo "</p>";
/******* Retrieve user's passwrod from the database
********/
/** Construct the SQL to retrieve password */
//$sql = "SELECT password from users where username =
\"".$user."\"" ;
$sql = sprintf("SELECT password from users where username
='%s'",
mysqli_real_escape_string($link, $user));
if($result = mysqli_query($link, $sql)){
if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
$pw = $row["password"];
/** Check if user supplied the correct password */
if ($pw == $password){
echo "<strong>Login
Succeeded</strong><br>";
echo "<a href=\"http://www.google.com\"> Now you can go
to my wonderful
page!</a>";
//header('Location: http://www.google.com'); exit;
}
else{
/* Incorrect password */
echo "<strong>Login Failed - Wrong
password</strong><br>";
}
}
else{
// mysqli_num_rows($result) is zero, meaning no such
username
echo "<strong>Could not log in - No such
user</strong><br>";
}
}
else{
//$result is false -> error getting password
echo "<strong>Login
Failed</strong><br>";
}
mysqli_close($link);
}
?>
</body>
</html>
5. Create a html file called login.html. Code it yourself like
the following figure
The html code is provided but it is not finished. Please use
“username” and “password”
for the two input boxes, respectively.
<!DOCTYPE html>
<html>
<head>
<title>
Login
</title>
<style type="text/css">
label{
display: inline-block;
float: left;
clear: left;
width: 100px;
text-align: left; /*Change to right here if you want it close
to the inputs*/
}
input {
display: inline-block;
float: left;
}
</style>
</head>
<body>
<h3> If you are a registered user, please log in
</h3>
<form action="login.php" method="POST">
//finish the code here
</form>
</body>
</html>
6. Right now, you should have register.html, register.php,
login.html, login.php and welcome.index
Welcome! If you haven't registered, please click register. Register here! If you've registered, please log in. Login here! You can use the following html code:
If you are a registered user, please log in Username: Password: Login
just give code for Mysql user table and register.html and //finish the code here Perform these tasks first: (a) Create a
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
just give code for Mysql user table and register.html and //finish the code here Perform these tasks first: (a) Create a
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!