0

So i am trying to have 2 seperate if statements in my index.php file but for some reason the if statements are not working. Basically I am using jquery to send values using $.get to the php function

index.php:

if (isset($_GET['year']) && isset($_GET['month']) && isset($_GET['monthStr']))
{
}

if (isset($_GET['yearPaid']) && isset($_GET['monthPaid']) && isset($_GET['personName_id']))
{
}

Here is the relevant js (the second if statement does not work):

$.get("index.php", { 'personName_id':user_id, 'monthPaid':month, 'yearPaid':year})
    .done(function(data) {
        console.log($(data).html());
        entry.animate({
            opacity: 0.2,
        }, 1000 );
    });

any ideas guys?

EDIT: when i mean 'not working', the second if statement is not firing the first one working fine.

EDIT: WOW! I FEEL SO STUPID! turns out the 2nd if was nested inside the first. Sorry for the waste of time guys I really appreciate your help though

EDIT: still same problem :P

EDIT: Some how it magically fixed turns ut my ajax request from jquery was messed up

Rohan Bhangui
  • 353
  • 2
  • 10
  • 3
    What does 'not working' mean? Do they crash? Pass when they should fail? Are all the fireld being set? Is there any debugging code in your PHP? – andrewsi May 24 '13 at 18:23
  • 1
    You named the parameter `yearPaid` and then tried to access it as `year` and `yearPaid`. One of the two will be not set in php. – Kevin B May 24 '13 at 18:24
  • I would use array_key_exists in stead of isset: http://stackoverflow.com/questions/3210935/difference-between-isset-and-array-key-exists – Pevara May 24 '13 at 18:25
  • @PeterVR: ya i will look into that. this is just a first run – Rohan Bhangui May 24 '13 at 18:26
  • @KevinB: would i use a global var in js for the year then? – Rohan Bhangui May 24 '13 at 18:27
  • @RohanBhangui i don't think that would affect anything. – Kevin B May 24 '13 at 18:28
  • @KevinB: the funny thing is the first one is firing and i wonder why the second one is firing. whether they are named yearPaid or year for the same value it should not make a difference right? – Rohan Bhangui May 24 '13 at 18:31
  • The first one working fine doesn't make any sense. That doesn't match what your javascript is doing. – Kevin B May 24 '13 at 18:40
  • the first if statement is fired with a different snippet of my script....the purpose of showing the first if statement is to show that there are 2 if statements there and the second is not firing – Rohan Bhangui May 24 '13 at 18:42
  • { 'personName_id':user_id, 'monthPaid':month, 'yearPaid':year}, you do not need to put quotes -> { personName_id :user_id, monthPaid :month, yearPaid :year} – Frédéric Clausset May 24 '13 at 18:43
  • keep that in mind but that is just formatting but thanks anyways – Rohan Bhangui May 24 '13 at 18:44
  • What's the output if you do a print_r on $_GET? – Luigi Siri May 24 '13 at 19:02
  • when added between the ifs: Array ( [year] => 2013 [month] => 5 [monthStr] => May ) <--- I should explain the first if returns those values – Rohan Bhangui May 24 '13 at 19:05
  • Is that after doing the request with the JS code you posted? – Luigi Siri May 24 '13 at 19:19
  • yes the js runs $.get and then the 2nd if statement is suppose to happen and then the .done is after the request is completed, when the request completely for now it returns undefined – Rohan Bhangui May 24 '13 at 20:07
  • FWIW `isset()` can take multiple values, so you can do `isset($_GET['year'],$_GET['month'],$_GET['monthStr'])` and that is the same as `isset($_GET['year']) && isset($_GET['month']) && isset($_GET['monthStr'])` – Ryan B May 25 '13 at 17:57
  • both eed to be fired cause the info provided at both is different – Rohan Bhangui May 28 '13 at 00:19

2 Answers2

0

Your first if isn't firing becuase you are not sending anything that the if is testing for.

The second should be firing.

Orangepill
  • 24,500
  • 3
  • 42
  • 63
  • thats the thing the first one is firing and firing properly the second one is not firing and when i try to echo something in side nothing gets echoed – Rohan Bhangui May 24 '13 at 18:28
  • that might be a relevant add to the question... It is unclear what is occurring as a result to this "not working" – Orangepill May 24 '13 at 18:31
  • Edit made. I tried to use an elseif statement instead of if statement for the 2nd if but that did not work either – Rohan Bhangui May 24 '13 at 18:34
0

i emptied my cache and did hard relaod and rewrote my jquery side of the ajax request and it worked

Rohan Bhangui
  • 353
  • 2
  • 10