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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?