Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 09-02-2013, 12:16 AM
bzcomputers's Avatar
bzcomputers bzcomputers is offline
 
Join Date: Apr 2012
Location: TX
Posts: 503
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Custom Page will not render after adding database connection

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:

Code:
// 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.
Reply With Quote
  #2  
Old 09-02-2013, 01:27 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #3  
Old 09-02-2013, 03:16 AM
bzcomputers's Avatar
bzcomputers bzcomputers is offline
 
Join Date: Apr 2012
Location: TX
Posts: 503
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well after hours of trying to track it down it came out to be a simple solution.
Had to replace:

Code:
print_output($templater->render());

With:


Code:
echo($templater->render());

before the php close.


Can anyone shed light on why print_output wouldn't work in this situation?
Reply With Quote
  #4  
Old 09-02-2013, 09:09 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 09-02-2013, 10:27 PM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #6  
Old 09-03-2013, 04:35 AM
bzcomputers's Avatar
bzcomputers bzcomputers is offline
 
Join Date: Apr 2012
Location: TX
Posts: 503
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
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.
Reply With Quote
  #7  
Old 09-03-2013, 05:54 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by bzcomputers View Post
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.
Reply With Quote
  #8  
Old 09-03-2013, 06:50 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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().
Reply With Quote
2 благодарности(ей) от:
Lynne, tbworld
  #9  
Old 09-04-2013, 12:43 AM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
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"
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:55 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04946 seconds
  • Memory Usage 2,249KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (2)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete