The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
Inserting SQL in PHP Problem - please help
I'm trying to insert the following code in a hook but I have a syntax error and I can't seem to figure out how to make it work.
Code:
function prepare_output($id = '', $options = array()) { $this->block_data['longbox'] = '$db->query_first("SELECT * FROM " . TABLE_PREFIX . "formresults WHERE userid = '$bbuserinfo[userid]' ")'; } } Parse error: syntax error, unexpected T_VARIABLE in /home/righscom/public_html/addons/projectfanboy/vb/member.php(463) : eval()'d code on line 247 I'm pretty sure it's the usage of the double and single quotes in my query but I don't know how else to call for the information without it. Can anyone help me please? Here is the entire plug in code below: Code:
$blocklist = array_merge($blocklist, array( 'longbox' => array( 'class' => 'Longbox', 'title' => 'Resume', 'hook_location' => 'profile_left_last' ) )); class vB_ProfileBlock_Longbox extends vB_ProfileBlock { var $template_name = 'memberinfo_block_longboxes'; function confirm_empty_wrap() { return false; } function confirm_display() { return ($this->block_data['longbox'] != ''); } function prepare_output($id = '', $options = array()) { $this->block_data['longbox'] = '$db->query_first("SELECT * FROM " . TABLE_PREFIX . "formresults WHERE userid = '$bbuserinfo[userid]' ")'; } } |
#2
|
||||
|
||||
Code:
function prepare_output($id = '', $options = array()) { $this->block_data['longbox'] = '$db->query_first("SELECT * FROM " . TABLE_PREFIX . "formresults WHERE userid = '$bbuserinfo[userid]' ")'; } Code:
function prepare_output($id = '', $options = array()) { $this->block_data['longbox'] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "formresults WHERE userid = '$bbuserinfo[userid]' "); } Cheers |
#3
|
||||
|
||||
Quote:
Fatal error: Call to a member function query_first() on a non-object in /home/righscom/public_html/addons/projectfanboy/vb/member.php(463) : eval()'d code on line 247 I didn't realize it until now but I think that the error above is actually a step in the right direction, because it's telling me that I need to fix something else. I did some googling on that error and from what I can tell I need to globalise the variable $db->query_first by adding global $db->query_first; in my code. After adding it to the top of the plugin my profile page loads but has the following error and now I feel like I'm back at step 1. Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /home/righscom/public_html/addons/projectfanboy/vb/member.php(463) : eval()'d code on line 223. Here's what my plugin looks like now. Code:
global $db->query_first; $blocklist = array_merge($blocklist, array( 'longbox' => array( 'class' => 'Longbox', 'title' => 'Resume', 'hook_location' => 'profile_left_last' ) )); class vB_ProfileBlock_Longbox extends vB_ProfileBlock { var $template_name = 'memberinfo_block_longboxes'; function confirm_empty_wrap() { return false; } function confirm_display() { return ($this->block_data['longbox'] != ''); } function prepare_output($id = '', $options = array()) { $this->block_data['longbox'] = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "formresults WHERE userid = '$bbuserinfo[userid]' , AND title = 'Resume' "); } |
#4
|
||||
|
||||
Your $db variable ain't global. XP
Before that line, insert: PHP Code:
Not sure that this is your only error, but that's where you're having the trouble at the moment. --------------- Added [DATE]1262191036[/DATE] at [TIME]1262191036[/TIME] --------------- Basically, inside any function, if $db is not specifically declared as a global variable, it will only look at the variables LOCAL to the function. |
#5
|
||||
|
||||
Quote:
Code:
function prepare_output($id = '', $options = array()) global $db; { $this->block_data['longbox'] = $db("SELECT * FROM " . TABLE_PREFIX . "formresults WHERE userid = '$bbuserinfo[userid]' , AND title = 'Resume' "); } Parse error: syntax error, unexpected T_GLOBAL, expecting ';' or '{' in /home/righscom/public_html/addons/projectfanboy/vb/member.php(463) : eval()'d code on line 247 EDIT: Oh wait, that's not the same error. To the interweb! |
#6
|
||||
|
||||
PHP Code:
should be like this.. PHP Code:
|
#7
|
||||
|
||||
Quote:
Parse error: syntax error, unexpected T_IF, expecting T_FUNCTION in /home/righscom/public_html/addons/projectfanboy/vb/member.php(463) : eval()'d code on line 252 |
#8
|
||||
|
||||
Not that I'm not willing to help, but you might want to brush up on your PHP if you're not understanding these errors. XP
See the error? It ran into a "if" statement when it was expecting a "function" statement. Pretty straight-forward. Now take a look at the line numbers--all of this is erring on line 463, inside of an eval'd code, see? That almost always means that it's a Plugin causing your woes, and if you look on line 463 in member.php, you will see that there's a hook there for plugins. Now, the second number is "252". Notice that your previous error with misplacing the global was on line 247, so this new error is about 5 lines after that. This means that it's probably right at the end of this plugin OR it's right near the beginning of the next plugin that's loaded. (Without seeing the entire modifications you've made to this plugin, none of us can really tell you for certain, though.) So post your complete edited code, and we'll try to help you out, but be sure to look at a few PHP Tutorials so you can get a better grasp on the PHP syntax. :3 --------------- Added [DATE]1262194924[/DATE] at [TIME]1262194924[/TIME] --------------- Ah. >.> PHP Code:
|
#9
|
||||
|
||||
DragonBlade,
I appreciate the help, and as you've pointed out I do need to brush up on my PHP. Actually I've never taken any courses on PHP or anything, everything I have learned is for the most part through trial and error or trying to decipher other people's work. I didn't understand this latest error right away but I did figure out that it ran into an IF statement, I just can't figure out where. Here is my member_block_resume template: HTML Code:
<div class="alt1 block_row"> <ul class="list_no_decoration"> $block_data[resume] </ul> </div> Here is my plugin: Hook Location: member_build_blocks_start Title: Resume Execution Order: 5 Plugin PHP Code: Code:
$blocklist = array_merge($blocklist, array( 'longbox' => array( 'class' => 'resume', 'title' => 'Resume', 'hook_location' => 'profile_left_last' ) )); class vB_ProfileBlock_Longbox extends vB_ProfileBlock { var $template_name = 'memberinfo_block_resume'; function confirm_empty_wrap() { return false; } function confirm_display() { return ($this->block_data['resume'] != ''); } function prepare_output($id = '', $options = array()) { global $db; $this->block_data['resume'] = $db("SELECT * FROM " . TABLE_PREFIX . "formresults WHERE userid = '$bbuserinfo[userid]' , AND title = 'Resume' "); } Quote:
I know what variables are. I know what queries are. I didn't know what methods were (according to PHP.net they are the same thing as functions). And I still haven't found a definition of an object (I've found plenty of references to them, but not it's actual definition.) So if $db is a variable containing an object, is an object just what that variable represents? For instance if the variable $a = 1, would 1 be the object? Also, if methods and functions are the same thing, that means that the method/function in this case would be query_first which is a way to query the database, right? This kind of confused me because I thought I was supposed to drop query_first part like shown above. The sentence that really threw me for a loop was. Quote:
|
#10
|
||||
|
||||
Hmmm... Let me see what the best way to define it is...
You probably know what Arrays are. Like $bbuserinfo--it's an array that holds multiple variables inside of it. It can even hold other Arrays and even Objects. $bbuserinfo has several "keys" that hold values: $bbuserinfo['userid'] holds the userid, $bbuserinfo['username'] the name, and so on. Well, think of an Object as an Array that can hold it's own special functions (called "Methods"). $db is a Database Object that holds functions for communicating with the database. $db->query_first() is a method that returns one row from the database. $db->query_read() is a method that can return multiple rows. $db->query_write() allows you to write to the database. Objects can also hold regular variables; $vbulletin is an Object, and $vbulletin->userinfo is an array that holds the userinfo of the currently logged in user (like $bbuserinfo). $vbulletin->userinfo['userid'] holds the UserID of the currently-logged-in-user. Objects are really more of an advanced PHP topic that you really will only understand with experience, but they really make life a lot easier. Okay, now to get to what it is you wanted, heh. Add an end-curly-brace to the end of your code. PHP Code:
I'd like to help you out more on unerstanding Object, but I just can't think of a decent way to explain them without knowing just how far you've delved into PHP. XD But you seem very new to PHP, so really understanding Object might be a little beyond you at the moment. Still, if you want to take a looksee... http://php.net/manual/en/language.oop5.php Warning--you will NOT understand everything in one sitting; it's a very big topic to grasp. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|