Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Function is not getting called on clicking the button

This code is in first.php


function fas(){
    echo "fuction";
    echo "Anything";
}

if(isset($_POST['btn'])){
    fas();
}
?>

Code in second.php

<?php 
include 'first.php'
?>

<!DOCTYPE html>
<head>
    <title>Document</title>
</head>
<body>
    <button type= "submit" name = "btn"> click this</button>
</body>
</html>

On clicking the button, function fas is not getting called. What’s the issue?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could put the button in a form tag, then the button like this:

<form action="/" method="post">
  <button type="submit">Submit</button>
</form>

Or you could do it like this:

<button onclick="function_name()">Submit</button>

The second one is going to call the function directly, and not go to a separate link like a form would.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading