View Full Version : Custom Page will not render after adding database connection
bzcomputers
09-02-2013, 12:16 AM
I have some custom pages that I have moved the variables from the .php file into a database.
I've tested the database connection on its own and everything works fine. But as soon as I add the database code to the vB custom page the page no longer renders (just shows a blank page).
Here is a sample of the database code I've tried to insert into the custom page:
// Get parameters from url query string
$db = new dbPDO();
$cruiseport_id = !empty($_GET['id'])?intval($_GET['id']):1;
// get all the values form your table limited to the first matching row (thre should only be one
$query = "SELECT * FROM cruiseports WHERE cruiseport_id = :cruiseportid limit 1";
// the prepare and bind methods prevent any sort of SQL injection (ie bad stuff in the $id value)
$stmt = $db->prepare($query);
$stmt->bindValue(":cruiseportid",$cruiseport_id);
$stmt->execute();
// we are only expecting 1 row here...
$port = $stmt->fetch(PDO::FETCH_ASSOC);
Like I said the code on its own returns the results without issue but in a vB custom page .php it stops the page from rendering at all (just blank). But no errors are produced.
Lynne
09-02-2013, 01:27 AM
Are you sure you are even connecting to the database? Is there anything in your error_logs (if you don't know where they are, ask your host)?
Lynne Sands
vBulletin Support Staff
vBulletin.org Admin
bzcomputers
09-02-2013, 03:16 AM
Well after hours of trying to track it down it came out to be a simple solution.
Had to replace:
print_output($templater->render());
With:
echo($templater->render());
before the php close.
Can anyone shed light on why print_output wouldn't work in this situation?
Lynne
09-02-2013, 09:09 PM
print_output is a vbulletin function and so you would need to actually include the function or the file where the function is defined in order for it to work.
tbworld
09-02-2013, 10:27 PM
I noticed, when I saw this initial message, that you were asking why the page would not render, but there was not code listed to render your output. I guess I should have said something about the missing code and then I could have helped.
@Lynne of course is right -- Like always.
Function print_output --> /includes/functions.php
bzcomputers
09-03-2013, 04:35 AM
print_output is a vbulletin function and so you would need to actually include the function or the file where the function is defined in order for it to work.
Well, I believe it was included. The code from the first post was just showing what was added to a previously fully functioning vB custom page (created by following your article here: https://vborg.vbsupport.ru/showthread.php?t=228112). I have hundreds of custom pages that have been working perfectly but as soon as the above code was added to a few of them the print_output would no longer render the page. I had to change it to echo.
Lynne
09-03-2013, 05:54 PM
Well, I believe it was included. The code from the first post was just showing what was added to a previously fully functioning vB custom page (created by following your article here: https://vborg.vbsupport.ru/showthread.php?t=228112). I have hundreds of custom pages that have been working perfectly but as soon as the above code was added to a few of them the print_output would no longer render the page. I had to change it to echo.
It would only include the functions.php file if you added a line to include it. global.php doesn't 'include' the functions.php file automatically - you need to call any file you need for your page.
I think the problem is that $db is a global variable used by vbulletin, and the code you added overwrites it. print_output() not only echoes the output, but it also does some final tasks such as updating the user's last activity time, so you probably want to use it if possible.
If you change all occurences of $db to something else in the code you added, it will probably work with print_output().
tbworld
09-04-2013, 12:43 AM
I think the problem is that $db is a global variable used by vbulletin, and the code you added overwrites it. print_output() not only echoes the output, but it also does some final tasks such as updating the user's last activity time, so you probably want to use it if possible.
I looked at print_output last night and could not find any real reason for it not to work -- in fact I was puzzled by the whole thing. I totally missed the $db reassignment. As my kids would say "bombdigity" @kh99. (It make me sound young and trendy right? <grin>)
"I'm not worthy"
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.