douweilei2307 2016-06-13 23:48
浏览 52
已采纳

使用PHP和MySql数据库设置WebPages标题

So I have a database the program runs fine connects and all except for one thing I am trying to get the "forum_name" defined under my db and set it as my Title. Pretty much if I click on the link where it takes me to that post or forum page it will get whats under forum_name and print it as the Title.

This is db_connect.php

<?php
$db = new mysqli("localhost", "root", "","forum") or die("ERROR: With Connecetion");
 ?>

And this is the Reset:

<?php
session_start();
require"db_connect.php";
//get the page id
if(isset($_GET['id']) &&is_numeric($_GET['id'])){
    $id = $_GET['id'];
}else{
    die("Error! Does not exist!");
}
//check if Valid Id
 $idCheck = $db->query("SELECT * FROM forum_tabl WHERE forum_id = 'id'");
 if($idCheck->num_rows !==0){
     die("error");
 }
 $row = $idCheck->fetch_object();
 $sql = "SELECT post_id, post_title FROM forum_post WHERE forum_id? AND type= 'o'";
 if($query = $db->prepare($sql)){
     $query->bind_params('s', $id);
     $query->bind_result($post_id, $post_title);
     $query->execute();
     $query->store_result();
 }
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title><?= $row->forum_name?></title>
</head>

<body>

<div id="container">
    <!-- Theres content that will go here -->
</div>

</body>
</html>
  • 写回答

2条回答 默认 最新

  • doude4924 2016-06-14 00:12
    关注

    I think the Problem is in this line.

    $idCheck = $db->query("SELECT * FROM forum_tabl WHERE forum_id = 'id'");
    

    and You have to replace it as follows.

    $idCheck = $db->query("SELECT * FROM forum_tabl WHERE forum_id = '$id'");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 爬取1-112页所有帖子的标题但是12页后要登录后才能 我使用selenium模拟登录 账号密码输入后 会报错 不知道怎么弄了
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点