dongquming3255 2012-03-20 21:40
浏览 46
已采纳

资源ID#5:MySQL

<?php
//Sessions starten
session_start();
//Include stuff
include('conf.php');
//'Shortcuts' maken
$sname = $site['name'];
$shost = $site['host'];
$shostb = $site['hostb'];
//Verbinding maken met DB
$link = mysql_connect($database['host'], $database['username'], $database['password']) or die (mysql_error());
mysql_select_db($database['db'],$link) or die(mysql_error());
//Gegevens uit db halen
if(isset($_GET['page'])){
    $page['title'] = mysql_query("SELECT title FROM pages WHERE page = $_GET[page]");
}
else{
    $page['title'] = mysql_query("SELECT title FROM pages WHERE page = 'index.php'");
}
?>
<!doctype html>
<html lang="nl">
<head>
    <meta charset="utf-8" />
    <title><?php echo $sname;?>•<?php echo $page['title']?></title>

Does somebody know why this doesn't work? My DB structure is:

page |title

index.php|index

Sorry but I can't get this clear. The var dump of $page['title'] = resource(5) of type (mysql result). How can I fix this? Thanks for the help.

  • 写回答

4条回答 默认 最新

  • dtk31564 2012-03-20 21:41
    关注

    mysql_query returns a resource, you need to use mysql_fetch_array (or similar, e.g. mysql_fetch_assoc) on the resource to get the title value.

    For example:

    $res = mysql_query("SELECT title FROM pages WHERE page = 'index.php'");
    $page = mysql_fetch_assoc($res);
    
    // $page['title'] now contains the value (assuming there's an index.php page in the DB).
    

    Warning: your query is vulnerable to SQL injection.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄