php - isset 按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9324624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 06:34:27  来源:igfitidea点击:

php - isset button

phpisset

提问by Mert MET?N

i try to solve a problem but didnt succeed. I retrieve datas from google analytics and i have to send start and end date. I have two textbox and user select start and end date.However, but before user select enter image description herestart and end date. The problem occurs..

我试图解决一个问题,但没有成功。我从谷歌分析中检索数据,我必须发送开始和结束日期。我有两个文本框,用户选择在此处输入图片说明开始和结束日期。但是,在用户选择开始和结束日期之前。出现问题..

The place that i use isset is here,

我使用isset的地方就在这里,

This is my full html

这是我的完整 html

<?php
define('ga_email','[email protected]');
define('ga_password','************');
define('ga_profile_id','*******');

require 'gapi.class.php';
require 'connectDB.php';

$ga = new gapi(ga_email,ga_password);




?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>??erik</title>
<script language="javascript" type="text/javascript" src="datetimepicker.js">

//Date Time Picker script- by TengYong Ng of http://www.rainforestnet.com
//Script featured on JavaScript Kit (http://www.javascriptkit.com)
//For this script, visit http://www.javascriptkit.com 

</script>
</head>
<div></div>
<body>
    <table align="center">
        <tr> 
        <td><br />
    <br />
    <form action="#" method="post" name="formDates" id="form1" >
    <table width="303" height="40" border="0" align="center">
        <table width =""
  <tr>
    <td>Ba?lang?? Tarihi</td>
    <td>
      <label for="txtStartDate"></label>
      <input type="text" name="txtStartDate" id="txt1" value="" /><a href="javascript:NewCal('txt1','ddmmyyyy')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Ba?lang?? Tarihi Se?in">
      </a>
    </td>
  </tr>
  <tr>
    <td>Biti? Tarihi</td>
    <td>
      <label for="txtEndDate"></label>
      <input type="text" name="txtEndDate" id="txt2" /><a href="javascript:NewCal('txt2','ddmmyyyy')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Biti? Tarihi Se?in">
      </a>

    </td>
  </tr> 
    </form>
        <tr>
             <td><input type="submit" name="btnSubmit" value="G?nder"</td>
        </tr>

</table>
    <table width="1250" height="26" align="center">
  <tr>

    <td width="138"><strong>Kanal Ad?</strong>
    <td width="150"><b>Kategori Ad?</b></td>
    <td width="130"><p><strong>Event Ad?</strong></td>
    <td width="145"><strong>Toplam</strong>

  </tr>
    </table>



            <?php

            if(isset($_POST['submit'])){     
                $startDate = $_POST['txtStartDate'];
                $endDate = $_POST['txtEndDate'];  
             }


             $arrDates = explode("-",$startDate);
             $startDate=$arrDates[2]."-".$arrDates[1]."-".$arrDates[0];
             $arrDates = explode("-",$endDate);
             $endDate = $arrDates[2]."-".$arrDates[1]."-".$arrDates[0];

             echo $startDate;
             echo $endDate;



            $ga->requestReportData(ga_profile_id,array('eventCategory','eventAction'),array('totalEvents'),$sort_metric=null,$filter='eventAction==InitPlayer',$start_date='2012-02-02',$end_date='2012-02-16');
            foreach($ga->getResults() as $result2);
            {
                echo $result2->geteventCategory();
                echo $result2->geteventAction();
                echo $result2->gettotalEvents();
            }


            $ga->requestAccountData();
            $mysql = new mysql(); 
            $mysql->connect();  
            $counter = 0;



            foreach($ga->getResults() as $result)
            {     
                 echo $result . ' (' . $result->getProfileId() . ")<br />";
                 echo "<br />";
                 $counter++;
            }

            $result = mysql_query("select profile_id from profiles");
            $num_rows = mysql_num_rows($result);



            if($counter != $num_rows)
            {
                $mysql->query("delete from profiles");

                foreach($ga->getResults() as $result)
                { 
                   $mysql->query("insert into profiles values(".$result->getProfileId().",'".$result."')");
                }
            }






            ?>

</td>
    </tr>
    </table>
</body>
</head>
</html>

what is wrong?

怎么了?

if a choose start and end date problems is solved , problems occurs before that i choose

如果解决了选择开始和结束日期的问题,那么在我选择之前就会出现问题

回答by Dieta Gratis

It must be isset($_POST["btnSubmit"])NOT submit

它必须isset($_POST["btnSubmit"])不是提交

submit = type btnSubmit = name of the button

提交 = 类型 btnSubmit = 按钮的名称

回答by Den

When your page is loading and $_POST['submit']is not set, your $_POST['txtStartDate']and $_POST['txtEndDate']are not set so $arrDatesis not set too. You need to check if these $_POST vars are set or not, to work with them.

当您的页面正在加载$_POST['submit']且未设置时,您的$_POST['txtStartDate']$_POST['txtEndDate']未设置因此$arrDates也未设置。您需要检查是否设置了这些 $_POST 变量,以使用它们。

回答by kingmaple

You have to use isset()on every variable, not just one variable. $_POST['txtStartDate']and $_POST['txtEndDate']and other variables are simply not defined, this means that they were not sent with the POSTrequest.

您必须isset()在每个变量上使用,而不仅仅是一个变量。$_POST['txtStartDate']and$_POST['txtEndDate']和其他变量根本没有定义,这意味着它们没有与POST请求一起发送。

回答by Juvanis

Undefined index txtStartDate, ...

It seems that your form may not be conforming to the same variable name specification with the one that you use in this php file. Make sure field names are matching within the form and here.

您的表单似乎与您在此 php 文件中使用的表单不​​符合相同的变量名称规范。确保字段名称在表单中和此处匹配。

And also you should make these checks in your php file after submission success: if(!isset($_POST['submit']))

并且您还应该在提交成功后在您的 php 文件中进行这些检查: if(!isset($_POST['submit']))

回答by Mischa

I think it should be:

我觉得应该是:

if(isset($_POST['submit']))

instead of:

代替:

if(!isset($_POST['submit']))

The exclamation mark in front of issetmeans not. Also I would check for the actual fields you want to use, not for $_POST['submit']:

前面的感叹号isset表示not。此外,我会检查您要使用的实际字段,而不是$_POST['submit']

if(isset($_POST['txtStartDate']) && isset($_POST['txtEndDate']))
{
    // Do something with $_POST['txtStartDate'] and $_POST['txtEndDate']
}

The reason you were getting the error is that $_POST['submit']does not exist. There is not inputelement with a nameattribute called submit. Beware of the difference between typeand name.

您收到错误的原因是$_POST['submit']不存在。没有input具有name名为的属性的元素submit。当心之间的差异typename

回答by Romi Halasz

if(!isset($_POST['submit']))

This means that if the submitbutton was NOTpressed. You should check if the $_POST['submit']is set, as a result of the form submission, like so:

这意味着如果没有按下提交按钮。作为表单提交的结果,您应该检查是否已设置,如下所示:$_POST['submit']

if(isset($_POST['submit']))

回答by Rocky

I guess it should be if(isset($_POST['submit']))instead of if(!isset($_POST['submit']))as !in the start means a negation

我想这应该if(isset($_POST['submit']))不是if(!isset($_POST['submit']))因为!在启动意味着否定