Vytvořte tabulku členů v databázi
CREATE TABLE `members` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` char(20) NOT NULL,
`name` char(30) NOT NULL,
`email` char(40) NOT NULL,
`pass` char(20) NOT NULL,
PRIMARY KEY (`id`)
);
Přidat uživatele do tabulky členů
INSERT INTO `members` VALUES ('1', 'user1', 'mr. x', '[email protected]', '123');
Stačí změnit proměnnou jako uživatele mysql na stránce connection.php
connection.php
<?php
$mysql_host = "localhost";
$mysql_user = "root";
$mysql_pass = "";
$mysl_database = "taxretur_login";
$conn = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
mysql_select_db($mysl_database, $conn);
?>
login.php
<?php
include("connection.php");
if(isset($_POST["submit"])) {
$username = $_POST["username"];
$pass = $_POST["pass"];
$sql = "SELECT * FROM members
WHERE username='$username' AND pass='$pass'";
$result = mysql_query($sql);
$numRows = mysql_num_rows($result);
if($numRows==1) {
session_start();
$_SESSION["username"] = $username;
header("Location: ./profile.php");
} else {
echo "Invalid Login Information";
}
}
?>
<form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
<table>
<tr><td>User Name</td><td><input type="text" name="username" /></td></tr>
<tr><td>Password</td><td><input type="password" name="pass" /></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Login" /></td></tr>
</table>
</form>
profile.php
<?php
session_start();
include("connection.php");
$username = $_SESSION["username"];
$sql = "SELECT * FROM members WHERE username='$username'";
$result = mysql_query($sql);
if($row = mysql_fetch_array($result)) {
$username = $row["username"];
$name = $row["name"];
$email = $row["email"];
echo "
<table>
<tr><td>User Name</td><td> : </td><td>$username</td></tr>
<tr><td>Name</td><td> : </td><td>$name</td></tr>
<tr><td>Email</td><td> : </td><td>$email</td></tr>
</table>
";
}
?>