Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The login_update.php code:
- <?php include "db.php";?>
- <?php include "functions.php"; ?>
- <?php if(isset($_POST['submit'])){
- $username = $_POST['username'];
- $password = $_POST['password'];
- $id = $_POST['id'];
- $query = "UPDATE users SET ";
- $query .= "username = '$username', ";
- $query .= "password = '$password' ";
- $query .= "WHERE id = $id"; //fara '' pt ca id in baza de date e integer
- $result = mysqli_query($connection, $querry);
- if(!$result) {
- die('Nu a trecut querry!'. mysqli_error($connection));
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Document</title>
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
- <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
- </head>
- <body>
- <div class="container">
- <div class="col-sm-6">
- <form action = "login_create.php" method = "post">
- <div class="form-group">
- <label for="username"><b>Username</b></label>
- <input type="text" class="form-control" name = "username">
- </div>
- <div class="form-group">
- <label for="password"><b>Password</b></label>
- <input type="password" class="form-control" name = "password">
- </div>
- <div class="form-group">
- <select name="id" id="">
- <?php
- showAllData();
- ?>
- </select>
- </div>
- <div class="form-group">
- <label for="submit"></label>
- <input type="submit" class="btn-primary" name = "submit" value = "UPDATE">
- </div>
- </form>
- </div>
- </div>
- </body>
- </html>
- The db.php code:
- <?php
- $connection = mysqli_connect('localhost', 'root', '', 'loginapp');
- if(!$connection) {
- die ('No database connection');
- }
- ?>
- The functions.php code:
- <?php include 'db.php'; ?>
- <?php
- function showAllData(){
- global $connection;
- $query = "SELECT * FROM users";
- $result = mysqli_query($connection, $query);
- if(!$result){
- die ("Query failed!" . mysqli_error());}
- while($row = mysqli_fetch_assoc($result)){
- $id = $row['id'];
- echo "<option value='$id'>$id</option>";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement