Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// INDEX.php ///
- <?php include('server.php'); ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title> Crud PHP and MySQL </title>
- <meta charset="UTF-8"/>
- <link rel="stylesheet" type="text/css" href="style.css">
- </head>
- <body>
- <table>
- <thead>
- <tr>
- <th>Name</th>
- <th>Address</th>
- <thcolspan="2">Action</th>
- </tr>
- </thead>
- <tbody>
- <?php while ($row = mysqli_fetch_array($results)) { ?>
- <tr>
- <td><?php echo $row['name']; ?></th>
- <th><?php echo $row['address'] ?></td>
- <td>
- <a href="#">Edit</a>
- </td>
- <td>
- <a href="#">Delete</a>
- </td>
- </tr>
- <?php } ?>
- </tbody>
- </table>
- <form method="post" action="server.php">
- <div class="input-group">
- <label>Name</label>
- <input type="text" name="name">
- </div>
- <div class="input-group">
- <label>Address</label>
- <input type="text" name="address">
- </div>
- <div class="input-group">
- <button type="submit" name="save" class="btn">Save</button>
- </div>
- </body>
- </html>
- ///// SERVER.php ///////////////////////////////////
- <?php
- $name = "";
- $address = "";
- $id = 0;
- //$servername = "localhost";
- //$username = "root";
- //$password = "Nandinho12";
- //$db_name = "crudphp";
- //connect to database
- $db = mysqli_connect('localhost', 'root', 'Nandinho12', 'crudphp');
- //$db->set_charset('utf8');
- //if save button is clicked
- if(isset($_POST['save'])) {
- $name = $_POST['name'];
- $address = $_POST['address'];
- $query = "INSERT INTO info (name, address) VALUES ('$name', '$address')";
- mysqli_query($db, $query);
- header('location : index.php');
- }
- $results = mysqli_query($db, "SELECT * from info");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement