0

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,

This is my full 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

2
  • Post the html form. why not test if $_POST['txtStartDate'] is set? Make sure to react accordingly if txtStartDate and textEndDate are not set by either sending back an error message or throwing an exception. Commented Feb 17, 2012 at 7:49
  • 1
    Are you sure in your html form, the input elements have a name attribute? Its hard to help without the HTML code, but that's my shot in the dark Commented Feb 17, 2012 at 7:55

7 Answers 7

3

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

submit = type btnSubmit = name of the button

Sign up to request clarification or add additional context in comments.

1 Comment

you are absolutely right isset($_POST["submit"]) will not work because he used "btnSubmit" and not submit
1

I think it should be:

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

instead of:

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

The exclamation mark in front of isset means not. Also I would check for the actual fields you want to use, not for $_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 input element with a name attribute called submit. Beware of the difference between type and name.

1 Comment

if(isset($_POST['txtStartDate']) && isset($_POST['txtEndDate'])) { $startDate = $_POST['txtStartDate']; $endDate = $_POST['txtEndDate']; echo $startDate; echo $endDate; } This works thank you !!
1
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.

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

Comments

1

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

Comments

1

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 POST request.

Comments

0

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

1 Comment

@MertMETİN Are you sure you are performing a post request? Please show your html.
0
if(!isset($_POST['submit']))

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.