Gustavo Muratalla Gustavo Muratalla - 5 months ago 10
MySQL Question

Setting the a WebPages Title with PHP and MySql database

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>

Answer

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'");