am new to joomla module development. i want to create a data entry module, where will be some input field, that will insert data into my custom table. by help this link and Kevin answer insert into database from Joomla form fields i create 2 input field and success to store data into my custom table, but i need more input field like "email, phone, address, age..." ect, so wat will be this line?if( (isset($lname)) || (isset($fname)) )
Asked
Active
Viewed 1,415 times
0
1 Answers
1
Do bare in mind that the answer that Kevin posted was 3 years ago and does not following Joomla coding standards.
To get data from input fields, you don't use $_POST
. you need to use JInput
$input = new JInput;
$post = $input->getArray($_POST);
$lname = $post["lname"];
$fname = $post["fname"];
// add more here
To insert data into your database table, use Joomla coding standards like so:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$columns = array('lname', 'fname'); // add more table columns here
$values = array($db->quote($lname), $db->quote($fname)); // add more values here
$query
->insert($db->quoteName('#_table_name'))
->columns($db->quoteName($columns))
->values(implode(',', $values));
$db->setQuery($query);
$db->query(); // Use for Joomla 2.5
$db->execute(); // Use for Joomla 3.x
I've added comments where you can add more data. Please note the last 2 lines of the code. Only use 1 of the lines depending on which version of Joomla you're using
Hope this helps

Lodder
- 19,758
- 10
- 59
- 100
-
Thanks Lodder. heartly tnx to you. i did it. sir hope you will stay with me, coz i have many question and hope you will teach me like this answer. Thank you again – Masum Nov 24 '13 at 16:14