我编写此代码以从图像链接数据库中提取,以便更新天气链接。但是,它不会将图像链接打印到urlspace:
<?php
/* This code establishes MySQL connection,creates a function that pulls URLs from database to update picture file ? */
$datab ="weather";
$connect = new PDO("mysql:host=localhost;dbname=$datab", "***", "*****");
function rainmaker($fname) {
$sql = $connect->query("SELECT link FROM `radar3` WHERE `name` = `$fname`");
while($result = $sql->fetch(PDO::FETCH_ASSOC)){
$url1 = urlencode($result['name']);
print $url1;
};
?>
//URL where the image link will be printed:
<P><A HREF="../showImage.php?&url=<?=rainmaker('**$fname**')?>.php">North Plains</A></P>
相反,它只打印php函数名称代码。
答案 0 :(得分:3)
使用反引号转义表名和列名,而不是引号
SELECT link FROM `radar3` WHERE `name` = '$fname'
仅对查询中的静态字符串使用引号。