I am a newbie to PHP and Chronoforms but dedicated! After much research, I have managed to make a form which populates fields from the VirtueMart user info table, at first using a specific registered users ID to link to the relevant fields in the database.
Having completed this I then wanted to make this dynamic to the logged in users ID and although I have trawled the forum and tried "many" suggestions none seem to work.
I know I am very close and ask if anyone can advise what I am doing wrong. I have given the relevant extract of part of the form below, showing part my PHP code. The first line is my attempt to make it dynamic and the following 2 lines are some of the "specific" ID reference which populate perfectly.
I would really appreciate any response to this.
Thanks
Having completed this I then wanted to make this dynamic to the logged in users ID and although I have trawled the forum and tried "many" suggestions none seem to work.
I know I am very close and ask if anyone can advise what I am doing wrong. I have given the relevant extract of part of the form below, showing part my PHP code. The first line is my attempt to make it dynamic and the following 2 lines are some of the "specific" ID reference which populate perfectly.
<?php
$db =& JFactory::getDBO();
$my =& JFactory::getUser();
$db->setQuery('SELECT company FROM #__vm_user_info WHERE user_id = "$my->id"');
$dbCompany = $db->loadResult();
$db->setQuery('SELECT first_name FROM #__vm_user_info WHERE user_id="62"');
$dbfirstname = $db->loadResult();
$db->setQuery('SELECT last_name FROM #__vm_user_info WHERE user_id="62"');
$dblastname = $db->loadResult();I would really appreciate any response to this.
Thanks
Hi alful,
I think that there's a problem with the quotes here:
Bob
I think that there's a problem with the quotes here:
WHERE user_id = "$my->id"'Please tryWHERE user_id = '.$my->id.';'or, if you prefer WHERE user_id = {$my->id};'Bob
The suggestion of WHERE user_id = '.$my->id.';' worked perfectly.
Thank you very much!
Thank you very much!
<?php
$db =& JFactory::getDBO();
$my =& JFactory::getUser();
$db->setQuery('SELECT company FROM #__vm_user_info WHERE user_id = "$my->id"');
$dbCompany = $db->loadResult();
$db->setQuery('SELECT first_name FROM #__vm_user_info WHERE user_id="62"');
$dbfirstname = $db->loadResult();
$db->setQuery('SELECT last_name FROM #__vm_user_info WHERE user_id="62"');
$dblastname = $db->loadResult();
?>Thanks for the tip,
this is an improvement of your code
<?php
$db =& JFactory::getDBO();
$my =& JFactory::getUser();
$query='SELECT company,first_name,last_name FROM #__vm_user_info WHERE user_id = '.$my->id;
$db->setQuery($query);
$row = $db->loadObject();
?>you can populate your fields whit this
<?php
$form->data['name'] = $row->first_name.' '.$row->last_name;
?>
This topic is locked and no more replies can be posted.
