![]() |
Query problem with username
Seems simple enough, but I have a way with making it difficult it seems. :(
I have a variable that is loaded, $username And I want to fill the variable $useremail from that username This will go in a php file. But I cant figure out how to do a query that will accomplish this. $username $useremail = sqlquery from the $username Can someone smak me with the obvious please? |
Here you go...
Code:
$tmpname = $vbulletin->db->query_first("SELECT email |
Thanks, giving it a try now.
Quick question?... can I do this to put it into an html template? Code:
<?php Reason asking about the html template is, I found where I need to inject this query is in an embedded html template within the php file. Code:
<?php "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING" in WHERE username = '" . \$username . "'"); I have to add the backslashes infront of $ to eliminate another error. --------------- Added [DATE]1368135094[/DATE] at [TIME]1368135094[/TIME] --------------- $HTML_header_t is the only place I can execute this sql query, with of course $useremail being printed in the body of that page.. Code:
<?php |
You cannot put php into a template. You need to put the php into a plugin and then you preregister the resulting variable for the variable you are going to use it in. It's not clear at all which template you are wanting to use this in so there is no way I can get more specific.
I can point you to this article about preregistering variables (near the end) - [vB4] Rendering templates and registering variables - a short guide |
Quote:
I am reading that and hopefully may find a solution. This isnt a template per se', at least not a stock vb template. It is a custom file and called by another custom file. It is a php file as you can see at the bottom of my last post for part of it. Unless that is a template by definition. --------------- Added [DATE]1368150006[/DATE] at [TIME]1368150006[/TIME] --------------- Lynne, I read that completely and I do understand what I have read, but that doesnt, nor can it, apply here. I know that my problem is the sql syntax here, and I cant seem to find the syntax issue. Thanks anyway, but still looking for a tad bit-o-help. |
When you use HTML and PHP mixed on a page, you use the .php extension for the file but you separate the PHP and HTML like this...
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> So something like this would be needed... Code:
<?php |
If you include or requite global.php you should be able to get any user information without an extra query, something like this:
$vbulletin->userinfo['email'] |
If you include the global.php file, you don't need to also include the init.php file.
|
You should probably use $vbulletin->db->escape_string($username) in the query, otherwise if a username has a special character it may cause an error.
|
Quote:
|
You would just insert it where you use $username in the query. For example in the code nhawk posted it would be:
Code:
$tmpname = $vbulletin->db->query_first("SELECT email |
I have attempted and tried every which way to make any of you all's suggestions, to my dismay unsuccessfully.
It seems something in the query string that is outputting a syntax error and it will not perform the query. "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING" Now, I know that there can be some sql differences in revision, I am currently running on "mySQL rev: 5.0.96-community-log". I know on another site I had to make some changes after performing an sql upgrade in rev, but I cant see here where my problem might be here. |
Looks like a typo or mismatched quotes or something like that. You'd have to post your exact code.
|
Quote:
I know I have to add a preceeding backslash to all points of $, and that doesnt change execution but on my setup adding the backslash removes the initial error. But now it hangs on : $tmpname = $vbulletin->db->query_first("SELECT email FROM " . TABLE_PREFIX . "user WHERE username = '" . $vbulletin->db->escape_string($username) . "'"); |
Hmm, well, it's true that I haven't tried any of that code, but it looks OK. You shouldn't have to add any backslashes to it if you have the quotes right, because the $vbulletin->db->escape_string($username) part isn't inside the quotes.
Maybe someone else will see something I missed. |
Did you say this is in a custom file? If it is, there's no need to use $vbulletin->db->query_first - just use PHP.
But, assuming its not (in all honesty I haven't read all of this), try this.. Code:
$tmpname = $vbulletin->db->query_first(" |
Reading this I believe you need to post your code. Are you querying for the current username, a selected username or creating a list for their email.
If I am reading in between the lines correctly, I think you have been trying to embed the query inside the escaped html string <-- you are calling an embedded template. What we need to do is restructure what you have so you can see your way clear. |
Quote:
IE: I run a third party product on my vb that uses a php based template, albiet that it is mixed with php and template html. And it works, and by generating a page consisting of a header/body/footer. In this template are variables like $username and a few others. $username is populated in the php file that calles this "template".php. And $username can and is used in the html part of the file. I have a need now to create a way of making $useremail work the same way. But the snag, or I would have it by now myself, the file that fills $username is encoded so that file can not be changed. My only option is to find a way to make it work by way of a query, in the template file as it isnt encoded. Otherwise I am SOL. |
Quote:
Is the outputting of the template encoded? (Not the template) Can you parse the output $username in php to extract the data you need for your query? Trying to understand a little further. Not all the questions I asked above will make sense under your code condition, but it will let me fill in the gaps of information. |
It is not a vb page nor template, the php files although running as a vb product modification, run independantly from vb short of the attachment to the database and other misc variables.
The page generated does not contain vb elements such as vb header or footer, and the body is independant and stand-alone. The output is not encoded, just the original process in the php files are. As a anote, I can unencode the calling file, but only to view its contents, I cannot run it outside of being encoded. Yes the $username can and is parsed in the outputting of the html generated page reletive to the user that the page is generated for. |
Okay I have the picture. Unfortunately, because of all the particulars, I doubt that I can help you without seeing code. Sorry :(
|
All times are GMT. The time now is 10:29 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|