lets say I have a single record with fields; id, username and password inside of a database. how do I use php to display the username from the first record field without using a while, for or if loop?
Can some write a script for me please?
<?php
session_start();
require_once 'config.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<?php
$name = $_SESSION["name"];
$email = $_SESSION["email"];
?>
<?php
echo "your name is " . $name. "<br>";
echo "your email address is " . $email. "<br>";
$sql = "SELECT username FROM users LIMIT 1";
$result = mysqli_fetch_object($sql);
echo = $result->username;
?>
</body>
</html>
this is the config.php file
<?php
/* Database credentials. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'root');
define('DB_NAME', 'users');
/* Attempt to connect to MySQL database */
$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
?>