You code can hardly accomplish anything. To come to PHP which is the server-side scripting, you must first have at least a good knowledge of HTML in order to build the client UI. To go further, then add CSS and JavaScript. Visit
http://www.w3schools.com/[
^]
Why? As you learn, you will find out that the PHP script will be the one that constructs the client UI in HTML dynamically and outputs to the browser for rendering. So how can learn PHP without knowing HTML first?
Having said that, I have prepared a sample code for you to explore at your own leisure.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "databasename";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, fullname FROM tablename";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table border='1'><tr><th>ID</th><th>Full Name</th></tr>";
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["id"]."</td><td>". $row["fullname"]."</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
I have drafted the code out of my mind, if there is any syntax or typo, you shall figure it too.
P.S. There are a lot of examples on the Internet that use the mysql_* extension. This has been deprecated, read
http://php.net/manual/en/changelog.mysql.php[
^] . Use
MySQLi[
^] instead.