doublel83422 2012-02-27 17:18
浏览 29
已采纳

带有php的RSS和查询中的变量

I'm trying to build a simple RSS feed for multiple users but i am facing problems with mysql and the feed.

Ive done a showrss.php and an RSS.php I have followed a tutorial on this, and it works as should out of the box. But, im trying to build it, using var's on the mysql query populating the RSS.

so the showrss.php will do this :

require_once "XML/RSS.php";
$rss =& new XML_RSS("http://domain.com/RSS.php");
$rss->parse();
foreach ($rss->getItems() as $item) {
  echo "<li><a href=\"" . $item['link'] . "\">" . $item['title'] . 
"</a></li>
";
}

Calling up the RSS.php file. The only thing wrong with the RSS.php is the mysql query. IT simply wont work with variables in the query, and im wondering if any of you guys could point me in the right direction.

This works :

$query = "select * from article where full_name = 'myname' limit 15";

this does'nt work :

$full_navn = $_SESSION['full_name'];
$query = "select * from article where full_name = '".$full_navn."' limit 15";

However, loading the RSS.php straight in the browser with the variable does work. Any ideas on how to get my variable into rss.php when viewing it through showrss.php ?

Greatly appreciate any input.

  • 写回答

1条回答 默认 最新

  • dszn2485 2012-03-07 18:11
    关注

    Pass your variable via $_GET to the RSS feed and avoid any possible missing session variable.

    Your showrss.php file would be something like this for a user with the name of flamingcarrot:

    $rss =& new XML_RSS("http://domain.com/RSS.php?fullname=flamingcarrot");
    

    Then your RSS.php file would be something along the lines of:

    $full_navn = $_GET['full_name'];
    $query = "select * from article where full_name = '".$full_navn."' limit 15";
    

    If you haven't already, and since it's going to be fiddadling with your SQL statements, bone up some on avoiding some SQL injection attacks with how to properly clean up that SQL query before you actually run it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法