0

How to get the date from database and echo on PHP page?

$query = $pdo->prepare('SELECT * FROM shop WHERE shopname=:shopname');
$query->bindParam(':shopname', $shopname, PDO::PARAM_STR);
$query->execute();

$result = $query->fetchAll(PDO::FETCH_ASSOC);
echo "$result['shopid']";

This gives me the following error:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

Max
  • 12,622
  • 16
  • 73
  • 101
alvin890101
  • 57
  • 1
  • 8

2 Answers2

4
echo "$result['shopid']";

This line is incorrect

echo $result["shopid"];
// OR
echo "{$result['shopid']}";
Jonathon
  • 15,873
  • 11
  • 73
  • 92
1

remove the double quotes, change

echo "$result['shopid']";

with

echo $result['shopid'];
user2092317
  • 3,226
  • 5
  • 24
  • 35