Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2009-03-18 20:54:06
- rheroux
- New Member
- Registered: 2008-03-24
- Posts: 5
Querying Based On Current Logged In User
Hi everyone, I’ve been tearing my hair out over the past couple of hours trying to figure this out. First, I’m using the rvm_if_privileged plugin on my site so that I can create consent/access required based pages.
I have the following function:
function returnAgentId($agentname) {
$agentname = trim($agentname);
$sql = "SELECT * FROM txp_agents WHERE name = '$agentname'";
echo $sql;
$result = mysql_query($sql) or die ("Could not execute query: ".mysql_error());
$row = mysql_fetch_array($result);
return $row['id'];
}
I’m passing <txp:rvm_privileged_user /> to the function like so:
$agentid = returnAgentId('<txp:rvm_privileged_user />');
For some reason or another when the query finally makes it to MySQL it’s coming out like:
SELECT * FROM txp_agents WHERE name = ''
However, you’ll notice in the function I have it echoing out the $sql variable right before I do the query and when it echoes that out to the browser it has the username in between the single quotes. Does anybody have the slightest idea what the heck might be going on here?
Offline
Re: Querying Based On Current Logged In User
You shouldn’t be using a literal tag as the parameter. Try this:
returnAgentId(rvm_privileged_user(array()));
Also, look at textpattern/lib/txplib_db.php for db helper functions, specifically safe_field(...)
.
Last edited by jm (2009-03-18 23:26:52)
Offline
#3 2009-03-19 00:37:51
- rheroux
- New Member
- Registered: 2008-03-24
- Posts: 5
Re: Querying Based On Current Logged In User
Ah, it all makes sense now! Thanks a lot that worked!
Offline