in this blog shows how to get auto value into html
suppose we want maintain student data
step 1) create database it may mysql or sqlite
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Create database
$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
echo "Database created";
} else {
echo "Error creating database: " . $conn->error;
}
$conn->close();
?>
step 2) write html to get value from above created database
<html>
<body>
<div>
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, firstname, lastname FROM student";
$result = $conn->query($sql);
if ($result->num_rows > 0) { // output data of each row
while($row = $result->fetch_assoc()) {
echo "<p>id: " . $row["id"]. "</p> - <p>Name: " . $row["firstname"]. "</p> " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
</div>
</body>
</html>
from above code we get data from mysql table which shows student first name and last name,
important note - always add id & set it to primary key, into table because it is unique value in case referenece required id value is good to compare.
please comment your query,remarks.
Nice
ReplyDelete