sql >> Database >  >> RDS >> Mysql

MySQL-gegevens weergeven aan klanten zodra ze inloggen

Maak een ledentabel in uw database

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`)
);

Een gebruiker toevoegen aan tafelleden

INSERT INTO `members` VALUES ('1', 'user1', 'mr. x', '[email protected]', '123');

Verander gewoon de variabele als uw mysql-gebruiker in page connection.php

verbinding.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>

profiel.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>
    ";
}
?>


  1. Kan geen tabel maken - ERROR 1064 (42000):er is een fout in uw SQL-syntaxis

  2. Hoe phpMyAdmin op CentOS 6 te installeren en configureren

  3. Hoe kan ik zien wat er in een Postgresql-tabelruimte staat?

  4. Overschakelen naar voorbereide afschriften