2

How can I run a MySQL query from the onclick event of an HTML button on my site?

For example if my button is created like so, how could I use this to run a MySQL query titled AddInfo

<p><button type="button">Run A SQL Stored Procedure</button></p>
2

You need PHP for that. Here's an example :

<html>
<form action='' method='POST'>
<input type='submit' name='submit' />
</form>
</html>

and then

if(isset($_POST['submit'])){
//execute mysql query
}

Use Sourcerer to include PHP scripts inside a custom HTML module.

EDIT :

How to use Sourcerer ?

  • After the plugin is installed, a button (CODE) is added below the WYSIWYG editor :

enter image description here

  • Clicking on Code button opens a pop-up, enter your code between {source} and {/source} tags like this:

enter image description here

  • Hit the green Insert button to add this code to your Article or Custom HTML module :)
  • 1
    You don't need to include html tags ;) they already exist in the template – Lodder Apr 16 '16 at 19:55
  • I have installed this extension, how to use it in my article so that I can use the syntax? Does Joomla auto-detect that the extension is installed and can use PHP? – NadineSmithJonesPicard Apr 17 '16 at 2:33
  • 1
    @NadineSmithJonesPicard Answer updated with Sourcerer tutorial ;) – saibbyweb Apr 17 '16 at 5:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.