will_1990 Posted December 12, 2008 Share Posted December 12, 2008 I want to know if i have saved query results as an array in one php file if i can use that in another, will it "remember" the input information for that user. i am using sessions for the user logon but no cookies, would this need to be implimented? many thanks Will Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/ Share on other sites More sharing options...
chronister Posted December 12, 2008 Share Posted December 12, 2008 If you have a file included, and in said included file a variable is set, then it is available inside the file that your including from as long as your not dealing with functions and such. Variable scope is what your looking for here. Nate Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713426 Share on other sites More sharing options...
will_1990 Posted December 12, 2008 Author Share Posted December 12, 2008 If you have a file included, and in said included file a variable is set, then it is available inside the file that your including from as long as your not dealing with functions and such. Variable scope is what your looking for here. Nate Im not sure i get you, does the page i want the variable to be on aswell need to be linked in some way to this file? Maybe you can give me more of an idea while i sear variable scope if i give u more info. I havea booking for, this is then printed with an array, then users can register and then logon, once they log on i want a button on that they can click that will bring up there previous results stored in the array. not sure that ramble helped but i think you helped me a little thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713431 Share on other sites More sharing options...
will_1990 Posted December 12, 2008 Author Share Posted December 12, 2008 So really because i have used the variable in the previous script "locally" i cannot actually use this variable externally. Would this mean i need to force my user to re-do his/her input (which is obviously annoying and also makes the previous input pointless. correct? thanks Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713436 Share on other sites More sharing options...
.josh Posted December 12, 2008 Share Posted December 12, 2008 You would store the info in a session variable. Session variables persist from page to page. Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713439 Share on other sites More sharing options...
will_1990 Posted December 12, 2008 Author Share Posted December 12, 2008 You would store the info in a session variable. Session variables persist from page to page. thats exactly what i want, although there is a problem When the user first chooses flight in and it gets stored in the array there is no session because at that point the user is not unique (or not registered), therefore making it impossible to create a session variable right? i dont know that much about session vars but logically that presents a problem? Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713440 Share on other sites More sharing options...
haku Posted December 12, 2008 Share Posted December 12, 2008 When the user first chooses flight in and it gets stored in the array there is no session because at that point the user is not unique (or not registered), therefore making it impossible to create a session variable right? Not at all. A session creates a file on the server with data on it, then puts a cookie on the user's machine with a reference to the file on the server. The cookie stays on the users machine until the browser is shut down, so you can start a session whether they are registered or not. Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713448 Share on other sites More sharing options...
chronister Posted December 12, 2008 Share Posted December 12, 2008 You can make them unique by starting a session and assigning a session var. page1.php <?php session_start(); $_SESSION['persistantVar1'] = 'This will be accessible as long as the session exists'; $_SESSION['persistantVar2'] = 'This will too'; ?> page2.php <?php session_start(); echo $_SESSION['persistantVar1']; echo '<br><br>'; echo $_SESSION['persistantVar2']; ?> page2.php will show.... This will be accessible as long as the session exists This will too Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713449 Share on other sites More sharing options...
will_1990 Posted December 12, 2008 Author Share Posted December 12, 2008 You can make them unique by starting a session and assigning a session var. page1.php <?php session_start(); $_SESSION['persistantVar1'] = 'This will be accessible as long as the session exists'; $_SESSION['persistantVar2'] = 'This will too'; ?> page2.php <?php session_start(); echo $_SESSION['persistantVar1']; echo '<br><br>'; echo $_SESSION['persistantVar2']; ?> page2.php will show.... This will be accessible as long as the session exists This will too sorry for sounding obtuse I assume i place the session at the top of the page and i can use $row (which is my array var) in that and then return the session later? Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713451 Share on other sites More sharing options...
will_1990 Posted December 12, 2008 Author Share Posted December 12, 2008 is this correct <?php $_SESSION['persistantVar1'] = ('$row'); $row is defined lower like this: <?php while($row = mysql_fetch_array($result)..... thanks Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713453 Share on other sites More sharing options...
chronister Posted December 12, 2008 Share Posted December 12, 2008 Do you want the entire array to be stored in the $_SESSION var? If so, then you can do it that way, but a better way would be to only store what you need. session_start goes at the top of the page before anything else, then as you work through the $row array, you can add the particular item to the session var. Hopefully that makes sense to ya.... Nate Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713455 Share on other sites More sharing options...
will_1990 Posted December 12, 2008 Author Share Posted December 12, 2008 Do you want the entire array to be stored in the $_SESSION var? If so, then you can do it that way, but a better way would be to only store what you need. session_start goes at the top of the page before anything else, then as you work through the $row array, you can add the particular item to the session var. Hopefully that makes sense to ya.... Nate Yeah it does thanks alot and lucky i do want it all so that makes it simple! thanks, lets see how i get on! Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713456 Share on other sites More sharing options...
will_1990 Posted December 12, 2008 Author Share Posted December 12, 2008 Right i have done this and then once the user has logged on also using a session i have put the array there. However, this seems to just print out $row lol does this mean i have not declared the session var properly? <?php session_start(); if(!session_is_registered(myusername1)){ header("location:main_logon_customer.php"); } ?> <!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=iso-8859-1" /> <link rel="stylesheet" href="dropdown2.css" type="text/css" /> <script type="text/javascript" src="dropdown.js"> </script> <script type="text/javascript" src="calendar.js"> </script> <script type="text/javascript" src="enablefield.js"> </script> <script type="text/javascript"> function greyText(one_way, return_date) { if (document.form1[one_way].checked) { document.form1[return_date].disabled=true; document.form1[return_flight].disabled=true; } else { document.form1[return_date].disabled=false; document.form1[return_flight].disabled=false; } } <title>Webair Contact Us</title> <link rel="StyleSheet" href="./mainstyle.css"type="text/css" media="screen"> </script> </head> <body> <div id="wrapper"> <table> <tr> <td> <img src="Webair--logo.gif" height= "65" width="240" align="top" /> </td> <td background="Banner--background.gif" height="60" align="right" width="817" > <h5 align="left"><?print 'You are Logged in as:';?> <?print $_SESSION['myusername1'];?></h5> <a class="hyperlink" href="http://www.cems.uwe.ac.uk/~wbennett/webair/main_logon.php"> <b> Staff login </b> </a> | <a class="hyperlink" href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html" > <b> Home </b> </a> | <a class="hyperlink" href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html" > <b> Booked Flights   </b> </a> </td> </tr> </table> <dl class="dropdown" > <dt id="one-ddheader" onmouseover="ddMenu('one',1)" onmouseout="ddMenu('one',-1)" > Home </dt> <dd id="one-ddcontent" onmouseover="cancelHide('one')" onmouseout="ddMenu('one',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html" class="underline" > Home </a> </li> </ul> </dd> </dl> <dl class="dropdown" > <dt id="two-ddheader" onmouseover="ddMenu('two',1)" onmouseout="ddMenu('two',-1)" > Contact us </dt> <dd id="two-ddcontent" onmouseover="cancelHide('two')" onmouseout="ddMenu('two',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact" class="underline" > Contact us </a> </li> </ul> </dd> </dl> <dl class="dropdown" > <dt id="three-ddheader" onmouseover="ddMenu('three',1)" onmouseout="ddMenu('three',-1)" > Flights </dt> <dd id="three-ddcontent" onmouseover="cancelHide('three')" onmouseout="ddMenu('three',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_refunds.html" class="underline" > Refund Policy </a> </li> </ul> </dd> </dl> <dl class="dropdown" > <dt id="four-ddheader" onmouseover="ddMenu('four',1)" onmouseout="ddMenu('four',-1)" > Travel Information </dt> <dd id="four-ddcontent" onmouseover="cancelHide('four')" onmouseout="ddMenu('four',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_flight_fares.html" class="underline" > Flight Timetable </a> </li> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_baggage.html" class="underline" > Baggage Information </a> </li> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_airport_info.html" class="underline" > Airport information </a> </li> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_travel_info.html" class="underline" > Travel documentation requirements </a> </li> </ul> </dd> </dl> <dl class="dropdown" > <dt id="five-ddheader" onmouseover="ddMenu('five',1)" onmouseout="ddMenu('five',-1)" > About Webair </dt> <dd id="five-ddcontent" onmouseover="cancelHide('five')" onmouseout="ddMenu('five',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_about.html" class="underline" > About Webair </a> </li> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact.html" class="underline" > Contact us </a> </li> </ul> </dd> </dl> <div style="clear:both" /> </div> <div id="content" > <div class="inner" > <table class="main" > <?php echo $_SESSION['persistantVar1']; ?> </div> </div> <<div id="footer"> <div id="inner"> <div id="footer2"> <p><hr class="line"></hr> <a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/main_logon.php"><b>Staff login</b></a> | <a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html"><b>Home</b></a> | <a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact.html"><b>Contact us</b></a> | <a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_about.html"><b>About Webair</b></a> <hr class="line2"></hr> </p> </div> </div> </div> </body> </html> thanks for this everyone!! Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713459 Share on other sites More sharing options...
chronister Posted December 12, 2008 Share Posted December 12, 2008 Ahhhh.. I missed that in your previous post.... your using single quotes which makes the value literal $_SESSION['persistantVar1'] = ('$row'); needs to be $_SESSION['persistantVar1'] = $row; And this needs to be below your actual while($row = mysql....) part. Otherwise $row is not yet defined. Nate Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713466 Share on other sites More sharing options...
will_1990 Posted December 12, 2008 Author Share Posted December 12, 2008 say i wanted to spilit my var like suggested how would i go about this like this? <?php $_SESSION['persistantVar1'] = (.$row['flight_num'].); considering that my variable is like this: <?php while($row = mysql_fetch_array($result)){ echo " <br><br> <table border='1' cellpadding=10> <tr> <td class='table'> <center><b> Flight Number </b></center> </td> <td class='table'> <center><b> Flight Route Selected </b></center> </td> <td class='table'> <center><b> Departure Time </b> </center> </td> <td class='table'> <center><b> Arrival Time </b></center> </td> <td class='table'> <center><b> Departure Date </b></center> </td> <td class='table'> <center><b> Return Date </b></center> </td> <td class='table'> <center><b> Number of Passengers Selected </b></center> </td> </tr> <tr> <td class='table'> <center> ".$row['flight_num']." </center> </td> <td class='table'> <center> ".$row['flight_route']." </center> </td> <td class='table'> <center> ".$row['departure_time']." </center> </td> <td class='table'> <center> ".$row['arrival_time']." </center> </td> <td class='table'> <center> ".$date_out." </center> </td> <td class='table'> <center> ".$date_return." </center> </td> <td class='table'> <center> ".$passenger_num['num_of_pass']." </center> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713467 Share on other sites More sharing options...
will_1990 Posted December 12, 2008 Author Share Posted December 12, 2008 is it valid to put <?php $_SESSION['persistantVar1'] = $row; ?> at the bottom of the page as long as u start the session at the top. As i find it tricky to insert this session info with ruining the while loop! and if i wanted to do each part of $row separately then it would be achieved by using this part of $row ".$row['flight_num']." thanks Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713470 Share on other sites More sharing options...
chronister Posted December 12, 2008 Share Posted December 12, 2008 Yes, that is correct on both accounts. Start the session at the top, and you can define session vars anywhere on the page. If you wish to define a specific session var, then yes you would do it like this... $_SESSION['flight_num'] = $row['flight_num']; Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713474 Share on other sites More sharing options...
will_1990 Posted December 12, 2008 Author Share Posted December 12, 2008 Sorry this is still not working, can you take a quick look please, here is the php where i collect the vars: <?php session_start(); print_r($_POST); ini_set ("display_errors", "1"); error_reporting(E_ALL); $error = FALSE; //database information $host = "stocks"; // Host name $username = "wbennett"; // Mysql username $password = "mysql5"; // Mysql password $db_name = "wbennett"; // Database name $tbl_name1 = "flight_webair"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Variables $flight_route_out = $_POST['flight_route_out']; $flight_route_return = $_POST['flight_route_return']; $date_return = $_POST['return_date']; echo $_POST['return_date']; $date_out = $_POST['departure_date']; echo $_POST['departure_date']; $passenger_num = $_POST['num_of_pass']; $one_way = (isset($_POST['one_way'])) ? $_POST['one_way'] : null; // make sure value is available first. $nonUSdate1 = $date_out; list($day,$month,$year) = explode('/',$nonUSdate1); $newDate1 = "{$month}/{$day}/{$year}"; $stamp = strtotime($newDate1); echo $stamp; $nonUSdate2 = $date_return; list($day,$month,$year) = explode('/',$nonUSdate2); $newDate2 = "{$month}/{$day}/{$year}"; $stamp2 = strtotime($newDate2); echo $stamp2; //To protect MySQL injection $flight_route_out = stripslashes($flight_route_out); $flight_route_return = stripslashes($flight_route_return); $flight_route_out = mysql_real_escape_string($flight_route_out); $flight_route_return = mysql_real_escape_string($flight_route_return); //Queries $sql1="SELECT * FROM `$tbl_name1` WHERE `flight_route` = '$flight_route_out'"; //$sql="SELECT * FROM $tbl_name1 WHERE flight_route_return='$flight_route_return'"; //Execute query 1 $result = mysql_query($sql1) or die(mysql_error()); if ($stamp < $stamp2){ echo "You cannot return before you leave!"; } if(mysql_num_rows($result) > 0){ ?> <!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=iso-8859-1" /> <link rel="stylesheet" href="dropdown2.css" type="text/css" /> <script type="text/javascript" src="dropdown.js"> </script> <script type="text/javascript" src="calendar.js"> </script> <script type="text/javascript" src="enablefield.js"> </script> <title> Booking Confirmation </title> <script type="text/javascript"> function greyText(one_way, return_date) { if (document.form1[one_way].checked) { document.form1[return_date].disabled=true; document.form1[return_flight].disabled=true; } else { document.form1[return_date].disabled=false; document.form1[return_flight].disabled=false; } } <title>Webair Contact Us</title> <link rel="StyleSheet" href="./mainstyle.css"type="text/css" media="screen"> </script> </head> <body> <div id="wrapper"> <table> <tr> <td> <img src="Webair--logo.gif" height= "65" width="240" align="top" /> </td> <td background="Banner--background.gif" height="60" align="right" width="817" > <a class="hyperlink" href="http://www.cems.uwe.ac.uk/~wbennett/webair/main_logon.php"> <b> Staff login </b> </a> | <a class="hyperlink" href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html" > <b> Home </b> </a> | <a class="hyperlink" href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html" > <b> Booked Flights   </b> </a> </td> </tr> </table> <dl class="dropdown" > <dt id="one-ddheader" onmouseover="ddMenu('one',1)" onmouseout="ddMenu('one',-1)" > Home </dt> <dd id="one-ddcontent" onmouseover="cancelHide('one')" onmouseout="ddMenu('one',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html" class="underline" > Home </a> </li> </ul> </dd> </dl> <dl class="dropdown" > <dt id="two-ddheader" onmouseover="ddMenu('two',1)" onmouseout="ddMenu('two',-1)" > Contact us </dt> <dd id="two-ddcontent" onmouseover="cancelHide('two')" onmouseout="ddMenu('two',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact" class="underline" > Contact us </a> </li> </ul> </dd> </dl> <dl class="dropdown" > <dt id="three-ddheader" onmouseover="ddMenu('three',1)" onmouseout="ddMenu('three',-1)" > Flights </dt> <dd id="three-ddcontent" onmouseover="cancelHide('three')" onmouseout="ddMenu('three',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_refunds.html" class="underline" > Refund Policy </a> </li> </ul> </dd> </dl> <dl class="dropdown" > <dt id="four-ddheader" onmouseover="ddMenu('four',1)" onmouseout="ddMenu('four',-1)" > Travel Information </dt> <dd id="four-ddcontent" onmouseover="cancelHide('four')" onmouseout="ddMenu('four',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_flight_fares.html" class="underline" > Flight Timetable </a> </li> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_baggage.html" class="underline" > Baggage Information </a> </li> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_airport_info.html" class="underline" > Airport information </a> </li> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_travel_info.html" class="underline" > Travel documentation requirements </a> </li> </ul> </dd> </dl> <dl class="dropdown" > <dt id="five-ddheader" onmouseover="ddMenu('five',1)" onmouseout="ddMenu('five',-1)" > About Webair </dt> <dd id="five-ddcontent" onmouseover="cancelHide('five')" onmouseout="ddMenu('five',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_about.html" class="underline" > About Webair </a> </li> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact.html" class="underline" > Contact us </a> </li> </ul> </dd> </dl> <div style="clear:both" /> </div> <div id="content" > <div id="table_gen_1" > <div class="inner" > <br> <?php //THERE IS AN ERROR display error message if($error == TRUE) { echo '<h1>' . $output . '</h1>'; } else { ?> <h1><center> Confirm Booking </center></h1> <h3><b><u> Out-going Flight Information: </u></b></h3> <?php while($row = mysql_fetch_array($result)){ echo " <br><br> <table border='1' cellpadding=10> <tr> <td class='table'> <center><b> Flight Number </b></center> </td> <td class='table'> <center><b> Flight Route Selected </b></center> </td> <td class='table'> <center><b> Departure Time </b> </center> </td> <td class='table'> <center><b> Arrival Time </b></center> </td> <td class='table'> <center><b> Departure Date </b></center> </td> <td class='table'> <center><b> Return Date </b></center> </td> <td class='table'> <center><b> Number of Passengers Selected </b></center> </td> </tr> <tr> <td class='table'> <center> ".$row['flight_num']." </center> </td> <td class='table'> <center> ".$row['flight_route']." </center> </td> <td class='table'> <center> ".$row['departure_time']." </center> </td> <td class='table'> <center> ".$row['arrival_time']." </center> </td> <td class='table'> <center> ".$date_out." </center> </td> <td class='table'> <center> ".$date_return." </center> </td> <td class='table'> <center> ".$passenger_num['num_of_pass']." </center> </td> </tr> </table> <br> <form name='confirm' action='register.html' method='post'> <center> <input type='submit' value='Confirm Booking' name='submit' ></center> <br><br>"; } } $_SESSION['flight_num'] = $row['flight_num']; ?> </div> </div> </div> <div id="footer"> <div id="inner"> <div id="footer2"> <p><hr class="line"></hr> <a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/main_logon.php"><b>Staff login</b></a> | <a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html"><b>Home</b></a> | <a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact.html"><b>Contact us</b></a> | <a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_about.html"><b>About Webair</b></a> <hr class="line2"></hr> </p> </div> </div> </div> </body> </html> <?php }else{ echo 'Sorry, couldn\'t find any flights'; } ?> Here is where i wish to display it: <? session_start(); if(!session_is_registered(myusername1)){ header("location:main_logon_customer.php"); } ?> <?php session_start(); ?> <!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=iso-8859-1" /> <link rel="stylesheet" href="dropdown2.css" type="text/css" /> <script type="text/javascript" src="dropdown.js"> </script> <script type="text/javascript" src="calendar.js"> </script> <script type="text/javascript" src="enablefield.js"> </script> <script type="text/javascript"> function greyText(one_way, return_date) { if (document.form1[one_way].checked) { document.form1[return_date].disabled=true; document.form1[return_flight].disabled=true; } else { document.form1[return_date].disabled=false; document.form1[return_flight].disabled=false; } } <title>Webair Contact Us</title> <link rel="StyleSheet" href="./mainstyle.css"type="text/css" media="screen"> </script> </head> <body> <div id="wrapper"> <table> <tr> <td> <img src="Webair--logo.gif" height= "65" width="240" align="top" /> </td> <td background="Banner--background.gif" height="60" align="right" width="817" > <h5 align="left"><?print 'You are Logged in as:';?> <?print $_SESSION['myusername1'];?></h5> <a class="hyperlink" href="http://www.cems.uwe.ac.uk/~wbennett/webair/main_logon.php"> <b> Staff login </b> </a> | <a class="hyperlink" href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html" > <b> Home </b> </a> | <a class="hyperlink" href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html" > <b> Booked Flights   </b> </a> </td> </tr> </table> <dl class="dropdown" > <dt id="one-ddheader" onmouseover="ddMenu('one',1)" onmouseout="ddMenu('one',-1)" > Home </dt> <dd id="one-ddcontent" onmouseover="cancelHide('one')" onmouseout="ddMenu('one',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html" class="underline" > Home </a> </li> </ul> </dd> </dl> <dl class="dropdown" > <dt id="two-ddheader" onmouseover="ddMenu('two',1)" onmouseout="ddMenu('two',-1)" > Contact us </dt> <dd id="two-ddcontent" onmouseover="cancelHide('two')" onmouseout="ddMenu('two',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact" class="underline" > Contact us </a> </li> </ul> </dd> </dl> <dl class="dropdown" > <dt id="three-ddheader" onmouseover="ddMenu('three',1)" onmouseout="ddMenu('three',-1)" > Flights </dt> <dd id="three-ddcontent" onmouseover="cancelHide('three')" onmouseout="ddMenu('three',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_refunds.html" class="underline" > Refund Policy </a> </li> </ul> </dd> </dl> <dl class="dropdown" > <dt id="four-ddheader" onmouseover="ddMenu('four',1)" onmouseout="ddMenu('four',-1)" > Travel Information </dt> <dd id="four-ddcontent" onmouseover="cancelHide('four')" onmouseout="ddMenu('four',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_flight_fares.html" class="underline" > Flight Timetable </a> </li> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_baggage.html" class="underline" > Baggage Information </a> </li> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_airport_info.html" class="underline" > Airport information </a> </li> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_travel_info.html" class="underline" > Travel documentation requirements </a> </li> </ul> </dd> </dl> <dl class="dropdown" > <dt id="five-ddheader" onmouseover="ddMenu('five',1)" onmouseout="ddMenu('five',-1)" > About Webair </dt> <dd id="five-ddcontent" onmouseover="cancelHide('five')" onmouseout="ddMenu('five',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_about.html" class="underline" > About Webair </a> </li> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact.html" class="underline" > Contact us </a> </li> </ul> </dd> </dl> <div style="clear:both" /> </div> <div id="content" > <div class="inner" > <table class="main" > <?php echo $_SESSION['flight_num']; ?> </div> </div> <div id="footer"> <div id="inner"> <div id="footer2"> <p><hr class="line"></hr> <a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/main_logon.php"><b>Staff login</b></a> | <a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html"><b>Home</b></a> | <a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact.html"><b>Contact us</b></a> | <a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_about.html"><b>About Webair</b></a> <hr class="line2"></hr> </p> </div> </div> </div> </body> </html> Sorry about this, i feel very stupid.... Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713477 Share on other sites More sharing options...
chronister Posted December 12, 2008 Share Posted December 12, 2008 No worries, we all start somewhere.... <? session_start(); if(!session_is_registered(myusername1)){ header("location:main_logon_customer.php"); } ?> <?php session_start(); // this is the second time session is started on this page... look at the top... this whole block can be removed. ?> Down at the bottom of the page, where you have this line $_SESSION['flight_num'] = $row['flight_num']; echo $row['flight_num'] to see if it contains the data you want. If it does, then you know that $_SESSION['flight_num'] should contain the data too. Everything else looks right, the second session_start may be goofing things up. I am thinking it is, because your starting a session on page 1, then on page 2, you start session again, which should grab onto the previously started session. The 2nd session_start on that page may be starting an entirely new session which the $_SESSION['flight_num'] is not a part of. I may be wrong, as I frequently am, but try that and see what you get. Nate Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713482 Share on other sites More sharing options...
will_1990 Posted December 12, 2008 Author Share Posted December 12, 2008 hehe thanks I tried waht you said and i did not get any output at all when i echoed "echo $row['flight_num'];" in my php. I had also tried it before with just the first session overall still stuck with no output! how fustrating!! what to dooooo! thanks so much for your help Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713486 Share on other sites More sharing options...
redarrow Posted December 12, 2008 Share Posted December 12, 2008 session_start() //can only be used once on a page but all pages using the session's..... and if your cross scripting from one website to another you need to use session's in a database.. <?php session_start(); //<<< goes here no where else but all pages using the session's.... //code... ?> Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713489 Share on other sites More sharing options...
chronister Posted December 12, 2008 Share Posted December 12, 2008 If you got nothing when you echo'd that var, then your not getting the data from the database like you thought. Start there. Below this line $result = mysql_query($sql1) or die(mysql_error()); add this... echo mysql_num_rows($result); if you get a 0, then your not getting anything from the database, if you get 1 or greater, then you are getting something from the database. That part needs to get sorted first, then you can deal with setting session vars and such. Nate Quote Link to comment https://forums.phpfreaks.com/topic/136636-use-variable-from-external-php-file/#findComment-713503 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.