I was trying to use prepared statements, but it always throws me an SQL syntax error at line 1. My goal is to make this as secure as possible. The appended code works.
The GET value is formatted as a string (for instance: nmcxxwakfe) and originally dynamically generated, so there's no way to only allow specific values.
try {
$db = new PDO("mysql:dbname=somedb;host=localhost", "person", "mysupersecretpw" );
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );//Error Handling
$sql = "SELECT * FROM $value";
$result = $db->prepare($sql);
$result->execute();
$daten = $result->fetchAll();
} catch(PDOException $e) {
echo $e->getMessage();//Remove or change message in production code
}
Thanks for help!