Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $conn = new mysqli('localhost','root','','sample_db');
- if ($conn->connect_error) {
- die("Connection failed:".$conn->mysqli_error);
- }
- if(isset($_POST['username'])){
- $uname= $_POST['username'];
- $pass= $_POST['password'];
- $type= $_POST['type'];
- $str = "INSERT INTO tbl_users(username,password,type) VALUES('".$uname."','".$pass."','".$type."')";
- if ($conn->query($str)===TRUE) {
- echo "NEW data added";
- }else{
- echo "Error:".$conn->connect_error;
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- </head>
- <body>
- <form method="POST">
- Username: <input type="text" name="username"><br>
- Password: <input type="password" name="password"><br>
- Type: <input type="text" name="type"><br>
- <button>SUBMIT</button><br>
- </form>
- <form method="POST">
- Delete: <input type="number" name="delete">
- <button>DELETE</button>
- </form>
- <?php
- $del= $_POST['delete'];
- $sql = "DELETE FROM tbl_users WHERE id='$del'";
- if ($conn->query($sql) === TRUE) {
- echo "Record deleted successfully";
- } else {
- echo "Error deleting record: " . $conn->error;
- }
- $str= "SELECT * FROM tbl_users";
- $result = $conn->query($str);
- echo "<table border=1>";
- if ($result->num_rows>0) {
- while($row=$result->fetch_assoc()){
- echo "<tr><td><a href='https://www.google.com/webhp?hl=en&ictx=2&sa=X&ved=0ahUKEwj_rqT6i6LlAhXZc94KHZV4DhYQPQgH?id="
- .$row['id']."'>"
- .$row['id']."</a></td><td>"
- .$row['username']."</td><td>"
- .$row['password']."</td><td>"
- .$row['type']."</td></tr>";
- }
- }
- echo "</table>";
- $conn->close();
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement