Forums

problem in query with WHERE clause

padideh 18 May, 2011
Hi
as everyone knows chronoform saves the Id of form's submitter
but I wanna use their names instead of Id so I tried this

<?php
$id="{cf_user_id}";
$user =& JFactory::getUser($id);
echo $user->name;
?>

but it didn't work so I tried to use query

    $id='{cf_user_id}';
    $db =& JFactory::getDBO();
    $query = "SELECT name, username FROM `jos_users` WHERE `id` = ".$id;
    $db->setQuery($query);
    $result = $db->loadObject();
    echo $db->getErrorMsg();
    echo $result->name;

and the error is this :

You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use near '}' at line 1
SQL=SELECT name, username FROM `jos_users` where id = 62


what can I do ?
GreyHead 18 May, 2011
Hi padideh,

This line won't work as you can't use the {input_name} syntax in PHP:
$id="{cf_user_id}";
instead use
$id = $MyRow['cf_user_id'];


Bob
This topic is locked and no more replies can be posted.