The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
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? |
#2
|
|||
|
|||
Here you go...
Code:
$tmpname = $vbulletin->db->query_first("SELECT email FROM " . TABLE_PREFIX . "user WHERE username = '" . $username . "'"); $useremail = $tmpname['email']; |
Благодарность от: | ||
smirkley |
#3
|
|||
|
|||
Thanks, giving it a try now.
Quick question?... can I do this to put it into an html template? Code:
<?php $tmpname = $vbulletin->db->query_first("SELECT email FROM " . TABLE_PREFIX . "user WHERE username = '" . $username . "'"); $useremail = $tmpname['email']; ?> 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 \$tmpname = \$vbulletin->db->query_first("SELECT email FROM " . TABLE_PREFIX . "user WHERE username = '" . \$username . "'"); \$useremail = \$tmpname['email']; ?> "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 $HTML_header_t = <<< TEOL <meta http-equiv="Content-Type" content="text/html; charset={\$stylevar[charset]}" /> <html> <head> \$css </head> <body> ....etc |
#4
|
||||
|
||||
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 |
#5
|
|||
|
|||
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. |
#6
|
|||
|
|||
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"> <html xmlns="http://www.w3.org/1999/xhtml" <?php echo HTML_PARAMS; ?>> <head> <title><?php echo META_TAG_TITLE; ?></title> <body> etc.. So something like this would be needed... Code:
<?php define('CSRF_PROTECTION', true); require_once('./global.php'); require_once (CWD . '/includes/init.php'); $username = "Joe"; $tmpname = $vbulletin->db->query_first("SELECT email FROM " . TABLE_PREFIX . "user WHERE username = '" . $username . "'"); $useremail = $tmpname['email']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" <?php echo HTML_PARAMS; ?>> <head> <title><?php echo META_TAG_TITLE; ?></title> <body> My Email Address Is: <?php echo $useremail ?> etc.. |
#10
|
|||
|
|||
How would I reference that using $username to get $useremail?
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|