如何检查php中是否按下了输入类型按钮? [英] how to check if input type button is pressed in php?

查看:149
本文介绍了如何检查php中是否按下了输入类型按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

isset()函数可用于检查是否按下了输入类型提交但有没有办法检查是否按下了输入类型按钮?在我的代码中,该按钮除了调用.Onclick()事件上的函数之外什么都不做,然后刷新页面并在php中创建一个数据库条目......我希望它只在按下按钮后才能进行输入...并且由于其他原因,我无法使用提交类型...以下是一些代码:

The isset() function can be used to check if input type submit is pressed but is there any way to check if the input type button is pressed? In my code the button does nothing but call a function on .Onclick() event which then refreshes the page and makes a database entry inside php...and i want it to make the entry only after the button is pressed...and i cant use the submit type for other reasons...following is some code:

function send()
 {
 var events=document.getElementById("event").value;
 location.href="calm.php?day=" + xx + "&month=" + yy + "&year=" + zz + "&events=" + events;      
 }
<input name="Button" type="button" id="submit" onclick="send(this.form)" value="Button" />
<?php
session_start();
include_once "connect_to_mysql.php";
$day = $_GET['day'];
$month = $_GET['month'];
$year = $_GET['year'];
$events = $_GET['events'];
$userid = $_SESSION['id'];
if (isset($_POST['button']))
 {
   $sql = mysql_query("INSERT INTO events (userid,month,day,year,events) 
                       VALUES('$userid','$month','$day', '$year','$events')")  
          or die (mysql_error());
 }
 ?>


推荐答案

isset($ _ POST [ '按钮'])你错过了首都 B 。您需要将其与输入的 name 属性相匹配。

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

这篇关于如何检查php中是否按下了输入类型按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆