How to check if input type button is pressed in PHP?

孤街浪徒 提交于 2019-12-05 12:20:40

isset($_POST['Button']) you just missed the capital B. You need to match it the same as the input's name attribute.

you need to do that using ajax. so when a user clicks this button the page won't refresh.. there should be a page behind the seen does that for the user. whenever he clicks the button it accesses that page and upload whatever data you want...

edit: or you can just add a hidden input in the form when the button is clicked the hidden input value changes to i.e. true... then from php codes you can use the isset or other functions to validate whether the user clicked the button or not...

In the example you have, the simplest approach would be to add an extra variable to the parameters passed in &button_press=true or something like that and then you would know that the button had been pressed when you are receiving the information

'locrizak' answered right . Your button name is 'Button' and you tried to check presence of click on 'button' both are different . In such case if you are unsure of what is wrong , you may print the entire POST array using

print_r($_POST)

This will display all submitted values from form including button

Using isset() is the correct method to check whether a form element is present or not

Use

if(isset($_POST['Button'])){
  //code block for insertion,validation etc //
}

isset() function does not works with input type=button. so either we have to use input type=submit instead of button or some hidden type if we still want to use button.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!