Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "testweb";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT id, fname, sname,email FROM contacts";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- // output data of each row
- echo "<table width='80%' border='1'>";
- echo "<tr><th>ID</th><th>Name</th><th>Surname</th><th>Email</th></tr>";
- while($row = $result->fetch_assoc()) {
- echo "<tr>";
- echo "<td>" . $row["id"]. "</td><td>" . $row["fname"]. "</td><td>" . $row["sname"]. "</td><td>" . $row["email"]. "</td>";
- echo "</tr>";
- }
- echo "</table>";
- } else {
- echo "0 results";
- }
- $conn->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement