0
<?php
$paseoLocationTo=$_POST['locationTo'];
$paseoLocationFrom=$_POST['locationFrom'];
$PTime=$_POST['time'];

echo"The value of Location to is $paseoLocationTo </br>";
echo"The value of Location from is $paseoLocationFrom </br>";
echo"The value of time is $PTime </br>";

mysql_connect('localhost', 'root', '')
            or die(mysql_error());

    mysql_select_db('shuttle_service_system') 
    or die(mysql_error());

$TripID =mysql_query("
    SELECT DISTINCT Trip_ID as 'TripID'
    FROM trip
    WHERE Timeslot LIKE '$PTime' AND Location_From Like '$paseoLocationFrom' AND Location_To    LIKE '$paseoLocationTo'     
");
    echo "<form action='LastPage.php' method='post'>";
    while($check = mysql_fetch_array($TripID))
    **echo "<name='TripID' id='TripID'>" . $check['TripID'] . " ";**
    echo "<p class='sure'> Are you sure with your reservation? </p>";
    echo"<input type='submit' value='Submit' class='Log'>";
    echo"</form";
?>  

From another php file, this the LastPage.php

<?php
**$TripID=$_POST['TripID'];
echo"The value of trip ID is $TripID </br>";**
?>  

Hi guys I was wondering why I can't access the "TripID" variable in the other php file? I was accessing it before but now there seems to be a problem, am I doing it right? I'm sorry a php and SQL newbie.

2

4 Answers 4

1

You need to add

 <input type="text" name="TripID" value="'.$check['TripID'].'" ... />

in your form in order to retrieve values with $_POST['TripID'].

There is no such thing as

 **echo "<name='TripID' id='TripID'>" . $check['TripID'] . " ";**

which was found in your code.

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

1 Comment

For sure, I didn't correct all the mistakes, just the one pointed out in the question :)
1
**echo "<name='TripID' id='TripID'>" . $check['TripID'] . " ";**

Looks like that should be:

echo "<input type='text' name='TripID' id='TripID' value='" . $check['TripID'] . "' />";

If you don't want it to be editable, display it then add a hidden field:

echo $check['TripID'];
echo "<input type='hidden' name='TripID' id='TripID' value='" . $check['TripID'] . "' />";

Basically, you're not putting your trip id into an actual form tag, so it's not getting posted over to your LastPage.php.

Edit: fixed the first input to wrap the tripID in the value attribute.

4 Comments

Vinoth beat me to it. :)
I have always used value="myValue" to set up a default value to an input. Does <input type="text">myValue</input> as you suggested produce the same effects and is correct?
@destroydaworld no it's invalid HTML, input is a void element dev.w3.org/html5/markup/input.text.html#input.text
Yeah, I had the input fixed in the second block, but missed it in the first block. correct syntax is <input value="" />. Going to update it now.
0

Replace following lines

**echo "<name='TripID' id='TripID'>" . $check['TripID'] . " ";**

with

echo "<input type="hidden" name="TripID" value="'.$check['TripID'].'"  />";

So it will not be visible to user on current page but when you will post the Form, it will be available in $_POST['TripID'] variable.

One more thing your tag is not properly closed.

Use MySQLi and prepared statements to prevent SQL injection.

PS: accept the answer if its work for you.

Comments

0

Your form tag is not closed properly. It is now as echo </form";

It should be echo"</form>";

Also you didnt added name in input tag.

It should be

echo"<input type='submit' value="$check['TripID']" name="TripID" class='Log'>";

There is no name tag <name> but you used how?

2 Comments

echo" blankspace missing echo "; "$check['TripID']" dots missing " . $check['TripID'] . " You have errors in the answer omg don't advice people with wrong syntax
Thank you vinoth for spotting the missing ">" in form. :)

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.