Search code examples
phpif-statementbuttonclickexecute

execute php statement if button is clicked


I want to execute a PHP statement if my html button is clicked, so I created a button like this :

<form method="post"> <input name="logout" type="submit" id="submit" value="logout" /> </form>

And then i have my php if statement code :

if (isset($_POST['logout']))
	{
		echo "Hello world!";
	}

doesn't really work and I don't know why.


Solution

  • I am assuming that you have written your PHP code on the same page.

    When you press submit button, it requires form that. Please make sure that you have written form tag and action is the same url or the url of the page where you wrote PHP code.

    And as you have checked for post, your method of form must be post.

    If all things are correct then please specify your full code here