0

I am a beginner with Joomla. I am using template sitegroundJ16-2. I designed a form for around 9 text fields. I also made a table in the database. Now I want to write a query to connect to database to insert data in the dbase and retrieve data.

I am not able to figure out where to write query.

In the article where I designed that form? Where can I locate my articles in directory structure?

Tim
  • 35,413
  • 11
  • 95
  • 121
user1512411
  • 63
  • 3
  • 10

2 Answers2

1

The code to connect to the database is:

$db = & JFactory::getDBO();

The code to insert a query would be something like this:

$query = "INSERT INTO `#__yourtable` (`firstname`, `lastname`) VALUES ('$firstname', '$lastname');";
$db->setQuery($query);

The code to retrieve information from a database could be something like this:

$query = 'SELECT * FROM #__yourtable ORDER BY id DESC';
$db->setQuery($query);

You won't be able to add this to a Joomla article, you will either need to create a component or find a free one and adapt it as GDP said, or create a module and embed it in an article.

Lodder
  • 19,758
  • 10
  • 59
  • 100
0

In spite of the very broad nature of your question, you'll need to write a component for joomla. A starting point Hello World would be the logical starting point, but I'd suggest finding and downloading a similar extension and modifying that. If it's just a form that you're looking to create, I'd strongly recommend one of the free extensions that do that for you that can be found at the JED.

GDP
  • 8,109
  • 6
  • 45
  • 82