2012-02-17 92 views
0

我試圖解決一個問題,但沒有成功。我從谷歌分析檢索數據,我必須發送開始和結束日期。我有兩個文本框和用戶選擇的開始和結束日期。但是,但在用戶選擇enter image description here開始和結束日期。出現該問題的..php - isset按鈕

,我使用isset是這裏的地方,

這是我的全功能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> 

有什麼不好?

如果選擇開始和結束日期的問題是解決了,之前發生的問題,我選擇

+0

郵政HTML表單的類型 btnSubmit按鈕=名稱。爲什麼不測試$ _POST ['txtStartDate']是否被設置?如果txtStartDate和textEndDate未通過發送錯誤消息或拋出異常來設置,請確保相應地作出反應。 – busypeoples 2012-02-17 07:49:24

+1

你確定在你的html表單中,輸入元素有'name'屬性嗎? (isset($ _ POST ['txtStartDate'])&& isset($ _ POST ['txtEndDate'])) { {0} {start} = $ _POST [*]如果沒有HTML代碼很難提供幫助,但這是我在黑暗中拍攝的 – xbonez 2012-02-17 07:55:36

回答

1

我覺得應該是:的

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

代替:

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

感嘆號在isset前意味着not。此外,我會檢查你想用實際的領域,而不是$_POST['submit']

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

你得到的錯誤的原因是,$_POST['submit']不存在。沒有input元素,name屬性稱爲submit。謹防typename之間的差異。

+0

[ 'txtStartDate']; $ endDate = $ _POST ['txtEndDate']; echo $ startDate; echo $ endDate; } 這個作品謝謝你! – 2012-02-17 08:08:00

+1

不客氣。我很高興它現在有效。 – Mischa 2012-02-17 08:11:14

1
Undefined index txtStartDate, ... 

看來你的形式可能不符合與您在使用一個相同的變量名規範這個PHP文件。確保字段名稱在表格和此處匹配。

,你也應該做這些檢查你的PHP文件提交成功後:if(!isset($_POST['submit']))

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

這意味着,如果提交按鈕被壓。你應該檢查$_POST['submit']設置,作爲表單提交的結果,就像這樣:

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

我想這應該是if(isset($_POST['submit']))而不是if(!isset($_POST['submit']))作爲啓動!意味着否定

+0

沒有什麼改變。 – 2012-02-17 07:54:49

+0

@MertMETİN你確定你正在執行發佈請求?請顯示你的html。 – Mischa 2012-02-17 07:57:16

+0

我發送了我的完整的php – 2012-02-17 07:58:49

1

當您的頁面正在加載並且$_POST['submit']未設置時,您的$_POST['txtStartDate']$_POST['txtEndDate']未設置,因此$arrDates也未設置。你需要檢查這些$ _POST變量是否設置,以與他們合作。

1

您必須對每個變量使用isset(),而不僅僅是一個變量。 $_POST['txtStartDate']$_POST['txtEndDate']和其他變量根本沒有定義,這意味着它們沒有與POST請求一起發送。

2

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

提交=按鈕