[Solved] I can’t view the database content on a php page [closed]


I have made an example how it could look with PDO (as i see you are just starting and i suggest to learn PDO as its not that hard)
This way you also are safe from SQL injections.

$host="127.0.0.1";
$db   = 'test';
$user="root";
$pass="";
$charset="utf8mb4";

$usid = 0;
$docname="";

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES   => false,
];
try {
     $pdo = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
     throw new \PDOException($e->getMessage(), (int)$e->getCode());
}

$stmt = $pdo->query("SELECT * FROM users WHERE id=?");
$stmt->execute([$usid]); 

$row = $stmt->fetch();
$docname = $row['docname'];

echo '
<div class="form-group">
  <input type="text" class="form-input" name="docname" id="name" placeholder="Your Name" value="'.$docname.'" />
</div>';

P.S. I have not tested it so fill your details and give it a try!

Here is really good website to learn all about PDO: https://phpdelusions.net/pdo

3

solved I can’t view the database content on a php page [closed]