0

In the code bellow I am trying to get the result of PNR Status

But don't know how to proper use it to call function

URL - https://github.com/ankitpise/OpenIrctc

error - Internal Server Error

<?php

include 'OpenIrctc.php';

$irctc = new OpenIrctc(6643704951); // $pnr_number = null by default
$irctc->set_language(); // english / hindi. English by default

$irctc->pnr_full_check(6643704951); // not necessary to pur $pnr number if initiated library with it.

$status= json_decode($data);
print_r($status);
var_dump($status);

?>
Alex Tartan
  • 6,736
  • 10
  • 34
  • 45
  • check what `print_r($irctc)` is having – ɹɐqʞɐ zoɹǝɟ Jul 19 '15 at 11:45
  • Internal Server Error – Olivia Nielsen Jul 19 '15 at 11:47
  • Check out this answer: http://stackoverflow.com/a/17693462/2025771. It will help you to figure out your exact error. I tried executing your code too and it works fine (though the response is false but it doesn't break anywhere) – littleibex Jul 19 '15 at 12:08
  • An internal server error is often a server misconfiguration, such as a bad `.htaccess`, rather than a php issue. – spenibus Jul 19 '15 at 12:19
  • Check your web server's `error.log` file, and [enable php's error logging](http://stackoverflow.com/a/845025/189362) to see what's going on. Internal Server Error can mean a thousand things, without more details it's just guessing. – Bjorn Jul 19 '15 at 13:16

1 Answers1

1

Your 500 error is likely caused by not having $data declared.

Use it like so:

include 'OpenIrctc/OpenIrctc.php';

$irctc = new OpenIrctc(6643704951);
$irctc->set_language('hindi');
$data = $irctc->pnr_full_check();
print_r($data); 

Also, the script does not return a json (pnr_full_check() calls reader_array() which returns an array)

This is the output:

Array
(
    [6643704951] => Array
        (
            [status] => success
            [train_info] => Array
                (
                    [train_no] => 13287
                    [train_name] => साउथबिहार एक्स.
                    [train_date] => 24- 7-2015
                    [train_from] => टाटानगर जं.
                    [train_to] => BIHA
                    [train_res_to] => BIHA
                    [train_res_from] => टाटानगर जं.
                    [train_res_class] => तृतीय वातानुकूलित
                )

            [यात्री 1] => Array
                (
                    [booking_status] => W/L    8,RLGN  
                    [current_status] => W/L    8
                )

            [चार्ट तैयार नहीं ] => Array
                (
                    [charting_status] => W/L    8
                )

        )

)

Alex Tartan
  • 6,736
  • 10
  • 34
  • 45
  • try replacing `include` with `require`. (it may be a wrong path or something and require will issue a fatal error - and you'll know). It's also useful to include the error message – Alex Tartan Jul 19 '15 at 11:53
  • I've made a test script and it works (can't find info for 6643704951, but it does return a response). So it's the 'wrong include path` that's breaking your script. Both `include` and `require` need absolute paths or relative paths from the script they're called from. If you did the `git clone` from the same folder your script is in, a 'OpenIrctc' folder was created and you'll have to use this path: `include 'OpenIrctc/OpenIrctc.php';` – Alex Tartan Jul 19 '15 at 12:05
  • 6643704951 is PNR number http://www.indianrail.gov.in/pnr_Enq.html for checking status – Olivia Nielsen Jul 19 '15 at 12:52
  • Please see updated answer (using "hindi" as the language and removing some parameters fixes the "failing" status) – Alex Tartan Jul 19 '15 at 13:14
  • Result - Array ( [6643704951] => Array ( [status] => failed [train_info] => Array ( [train_no] => [train_name] => [train_date] => [train_from] => [train_to] => [train_res_to] => [train_res_from] => [train_res_class] => ) [] => Array ( [charting_status] => ) ) ) – Olivia Nielsen Jul 19 '15 at 13:17
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83670/discussion-between-olivia-nielsen-and-alex-tartan). – Olivia Nielsen Jul 19 '15 at 13:31
  • hi @alex-tartan can you help me on this code - [link] (https://github.com/ramnew2006/quickpnr/blob/da0fcfb60743a28d7a9c402eb500546d8db1ea80/temp.php) need help on this code display results without storing in Database – Olivia Nielsen Nov 23 '15 at 05:34