unable to pass the value and get the response using GET meth

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sathya
Forum Commoner
Posts: 72
Joined: Sat Dec 12, 2015 7:26 am
Contact:

unable to pass the value and get the response using GET meth

Post by sathya »

Hi Friends,

I have two pages in my website index.php and trailtatus.php,when i pass the value from drop down to api pattern using php and json,it shows the trailstatus.php is empty page..

when i choose the train number and date in index.php then i press submit button it shows the empty result in the trailstatus.php page..kindly help me to resolve the problem.
our API Pattern will be lookks the below format:
API Pattern:
http://api.railwayapi.com/live/train/<t ... y/<apikey/
index.php

Code: Select all

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">

    <title>PNR Status </title>
  <head>
<body>
	<center>
<form action="trailstatus.php" method="get">
<tr>
<td>	Train Number:</td>
<td><input type="text" name ="train number"> </td> </br>
</tr>
<tr> 
<td> Select Date:</td>
<td><select>
  <option value="today"><?php echo date('Ymd', strtotime("today")); ?></option>
<option value="tomorrow"><?php echo date('Ymd', strtotime("tomorrow")); ?></option>
<option value="yesterday"><?php echo date('Ymd', strtotime("yesterday")); ?></option>
</select></td>
</tr>
<tr>
<td></br>
Submit:
</td>
<td><input type="submit" name ="submit">
</td>
</form>
</center>
  </body>
</html>

=================================================================
trailstatus.php

Code: Select all

<!DOCTYPE html
         <html
         <body
         <?php
         $json = '';
         if(isset($_GET['trainnumber'] && isset($_GET['doj'] )){
         $searchParam1 = $_GET['trainnumber'];
         $searchParam2 = $_GET['doj'];
         $replacedStr = str_replace(" ","",$searchParam1);
         $replacedStr1 = str_replace(" ","",$searchParam2);
         $url = 'http://api.railwayapi.com/live/train/' $replacedStr.'/doj/' $replacedStr1.'/apikey/ididntnoticeipostedmyapikeybutrequinixremoveditthankyou';
         $content = file_get_contents($url);
         $json = json_decode($content, true);
         }else{
          echo "something went wrong, please notify to admin [support@livetrainrunningstatus.co.in]";
         }
         $station = $json['route'] ['station'];
         $scharr = $json['route'] ['scharr'];
         $actarr = $json['route'] ['actarr']; 
         $status= $json['route'] ['has_departed'] [0] ['latemin'];
         ?>
		 <table>
  <tr>
    <th>station</th>
    <th>Sch.Arrival</th>
    <th>Act.Arrival</th>
    <th>Status/delay</th>

  </tr>
  <tr>
    <td><?php echo $station;?></td>
    <td><?php echo $scharr;?></td>
    <td><?php echo $actarr;?></td>
    <td><?php echo $status;?></td>
  </tr>
</table>
         </body
         </html
  
Thanks
Sathya
Last edited by requinix on Sat Dec 12, 2015 8:13 am, edited 1 time in total.
Reason: (cough)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: unable to pass the value and get the response using GET

Post by requinix »

sathya wrote:trailstatus.php

Code: Select all

<!DOCTYPE html
         <html
         <body
         <?php
Is that the actual code of the page? Where did all the >s go?
sathya
Forum Commoner
Posts: 72
Joined: Sat Dec 12, 2015 7:26 am
Contact:

Re: unable to pass the value and get the response using GET

Post by sathya »

Actually the train number and date should be go to this format in the code.http://api.railwayapi.com/live/train/<t ... y/<apikey/

.trainnumber as $replacedStr and doj as $replacedStr1

when i pass the value it will should return the values in the table format.
Thanks spammer for your reply..actually this is my step for learning and doing the project.
sathya
Forum Commoner
Posts: 72
Joined: Sat Dec 12, 2015 7:26 am
Contact:

Re: unable to pass the value and get the response using GET

Post by sathya »

Actaully i have used the format wrongly..missed the headers not properly..
<!DOCTYPE html>
<html>
<head>
<title>train status time table</title>
</head>
<body>
<?php
code goes here
?>
here the code for printing the tables
</body>
</html>
still getting the same issue.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: unable to pass the value and get the response using GET

Post by Celauran »

Code: Select all

$url = 'http://api.railwayapi.com/live/train/' $replacedStr.'/doj/' $replacedStr1.'/apikey/ididntnoticeipostedmyapikeybutrequinixremoveditthankyou';
That's going to throw errors because you're missing concatenation operators in a few places.
sathya
Forum Commoner
Posts: 72
Joined: Sat Dec 12, 2015 7:26 am
Contact:

Re: unable to pass the value and get the response using GET

Post by sathya »

Thanks for your suggestions.
i have updated your correction and getting the one new issues.help me to resolve this issue pls.

i have two files in my web server as index.php and livetrainstatus.php when i enter the train number and date getting the error as below..

Actually i want to know the reason why the error happening because all the response elements are get by the url only ,so i cant make define before that and make the index.
Notice: Undefined index: station in /var/www/vhosts/livetrainrunningstatus.co.in/httpdocs/livetrainstatus.php on line 23

Notice: Undefined index: scharr in /var/www/vhosts/livetrainrunningstatus.co.in/httpdocs/livetrainstatus.php on line 24

Notice: Undefined index: actarr in /var/www/vhosts/livetrainrunningstatus.co.in/httpdocs/livetrainstatus.php on line 25
station Sch.Arrival Act.Arrival Status/delay
JSON Response will be disaplyed in the format:
"response_code": 200,

"error": "",

"position": "Train has reached Destination and late by 5 minutes.",

"train_number": "12046",

"route": [

{

"no": 1,

"station": "CDG",


"has_arrived": false,
"has_departed": true,

"day": 0,

"distance": 0,

"scharr": "Source",

"schdep": "12:00",

"actarr": "00:00",

"actdep": "12:00",

"scharr_date": "19 Nov 2015",

"actarr_date": "19 Nov 2015",

"latemin": 0
index.php:

Code: Select all

<!DOCTYPE html>

<html lang="en">

  <head>

    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- The above 3 meta tags *must* come first in the head; any

other head content must come *after* these tags -->

    <meta name="description" content="">

    <meta name="author" content="">

 

    <title>PNR Status </title>

  <head>

<body>

    <center>

<form action="livetrainstatus.php" method="get">

<tr>

<td>    Train Number:</td>

<td><input type="text" name ="trainnumber"> </td> </br>

</tr>

<tr>

<td> Select Date:</td>

<td><select name="doj">

  <option value="today"><?php echo date('Ymd', strtotime("today")); ?></option>

<option value="tomorrow"><?php echo date('Ymd',

strtotime("tomorrow")); ?></option>

<option value="yesterday"><?php echo date('Ymd',
28
strtotime("yesterday")); ?></option>

</select></td>

</tr>

<tr>

<td></br>

Submit:

</td>

<td><input type="submit" value ="submit">

</td>

</form>

</center>

  </body>

</html>
livetrainstatus.php:

Code: Select all

<!DOCTYPE html>
<html>
 <head>
 <title>train status time table</title>
 </head>
<body>
<?php
$json = '';
if(isset($_GET['trainnumber']) && (isset($_GET['doj'] ) ))
{
$searchParam1 = $_GET['trainnumber'];
$searchParam2 = $_GET['doj'];
$replacedStr = str_replace(" ","",$searchParam1);
$replacedStr1 = str_replace(" ","",$searchParam2);
$url ="http://api.railwayapi.com/live/train/' .$replacedStr.'/doj/'
.$replacedStr1.'/apikey/*/";
$content = file_get_contents($url);
$json = json_decode($content, true);
}

else{
 echo "something went wrong, please notify to admin
[support@livetrainrunningstatus.co.in]";
}
$station = $json['route']['station'];
$scharr = $json['route']['scharr'];
$actarr = $json['route']['actarr'];
?>
<table>
  <tr>
    <th>station</th>
    <th>Sch.Arrival</th>
    <th>Act.Arrival</th>
    <th>Status/delay</th>

  </tr>
  <tr>
    <td><?php echo $station;?></td>
    <td><?php echo $scharr;?></td>
    <td><?php echo $actarr;?></td>
  </tr>
</table>
</body>
</html>

please help me to resolve the problem.your suggestions will help me lot.
Last edited by requinix on Wed Feb 03, 2016 11:37 pm, edited 1 time in total.
Reason: removing api key by request
Post Reply