How to get data from database and echo on php page?

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)


echo "$result['shopid']";

此行不正确

echo $result["shopid"];
// OR
echo "{$result['shopid']}";

remove the double quotes, change

echo "$result['shopid']";

with

echo $result['shopid'];
链接地址: http://www.djcxy.com/p/69934.html

上一篇: 解析错误:语法错误,空白错误

下一篇: 如何从数据库中获取数据并在php页面上回显?