Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
maybe this will work?
  • Loading branch information
btn15001 committed Dec 16, 2016
1 parent 133417e commit 8c16ae6
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions index.php
@@ -1,30 +1,33 @@
<html>

<table>

<tr>

<td>Name</td>
<td>Age</td>
</tr>
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

// sql to create table
$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";

if (mysqli_query($conn, $sql)) {
echo "Table MyGuests created successfully";
} else {
echo "Error creating table: " . mysqli_error($conn);
}

mysqli_close($conn);
?>

// Enter username and password
$username = root;
$password = root;

// Create database connection using PHP Data Object (PDO)
$db = new PDO("mysql:host=localhost;dbname=test", $username, $password);

// Identify name of table within database
$table = 'age';

// Create the query - here we grab everything from the table
$stmt = $db->query('SELECT * from '.$table);

// Close connection to database
$db = NULL;

while($rows = $stmt->fetch()){
echo "<tr><td>". $rows['Name'] . "</td><td>" . $rows['Age'] . "</td></tr>";
};
?>
</table>
</html>

0 comments on commit 8c16ae6

Please sign in to comment.