Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Menampilkan data MySQL ke klien setelah mereka masuk

Buat tabel anggota di database Anda

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

Tambahkan pengguna ke anggota tabel

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

Cukup ubah variabel sebagai pengguna mysql Anda di koneksi halaman.php

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


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Akses ditolak untuk pengguna '[email protected]' (menggunakan sandi:TIDAK)

  2. Tidak dapat Query file XML dengan OPENXML di SQL

  3. Menjalankan dua kueri SQL pada satu halaman php (SET + SELECT)

  4. Gunakan sphinx vs MySQL tanpa permintaan pencarian teks

  5. di mysql, saat hapus kaskade tidak berfungsi