Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // connect.php
- <?php
- $connection = mysqli_connect('localhost', 'root', 'root', 'loginapp');
- if(!$connection) {
- die("Database connection failed");
- }
- ?>
- // showDb.php
- <?php include 'connect.php' ?>
- <?php
- function showAllData() {
- global $connection;
- $query = "SELECT * FROM users";
- $result = mysqli_query($connection, $query);
- if(!$result) {
- echo(mysql_error());
- }
- while($row = mysqli_fetch_assoc($result)) {
- $id = $row['id'];
- echo "<option value='$id'>$id</option>";
- }
- }
- ?>
- // update.php
- <?php include 'showDb.php'; ?>
- <?php
- if(isset($_POST['sumbit'])) {
- $username = $_POST['username'];
- $password = $_POST['password'];
- $id = $_POST['id'];
- $query = "UPDATE users SET ";
- $query .= "username = '$username', ";
- $query .= "password = '$password' ";
- $query .= "WHERE id = $id ";
- $result = mysqli_query($connection, var_dump($query));
- if($result) {
- echo "Success";
- } else {
- die(mysql_error());
- }
- }
- ?>
- // some html...
- <select name="id" id="">
- <?php
- showAllData();
- ?>
- </select>
Add Comment
Please, Sign In to add comment