-1

I want to get the Value of a MySQL Cell in PHP. Here is my database table: values

structure

My Code:

<?php
$statement = $pdo->prepare("SELECT * FROM servers WHERE id = :id");
$servers = $statement->fetch();
$server = $servers['id'];
echo $server
?>

but it's not doing anything. (I want to get the value of the ID)

Blutudlut
  • 19
  • 2
  • 1
    You never set the id for the where startement. and you never execute your statement. see https://www.php.net/manual/de/pdostatement.fetch.php fro more informations – Jens Jul 29 '22 at 12:03
  • 1
    *"I want to get the value of the ID"* - It's not clear to me what you're trying to do, because the SQL query shown needs you to **give it** the value of `id`. You're trying to fetch an `id` value that you would need to already have in order to fetch it. Can you clarify the intent here? – David Jul 29 '22 at 12:03
  • 2
    You won't be able to just guess how PDO functions work. I recommend to check the official manual or follow some (reputable) tutorial. – Álvaro González Jul 29 '22 at 12:07
  • And here is one: https://phpdelusions.net/pdo#fetchcolumn – Your Common Sense Jul 29 '22 at 12:46

1 Answers1

-2

use the following query instead of your query

prepare($sql); `` $stmt->bind_param("i", $id);`` $stmt->execute();`` $result = $stmt->get_result(); `enter ` $server= $result->fetch_assoc();`` echo $server; `` ?>