spacepoet Posted April 25, 2011 Share Posted April 25, 2011 Hi: How do I transfer an ID to a 3rd page. Meaning: Events.php ... <a href="eventDetails.php?calID=<?=$row['calID'];?>"><?=$row['calName'];?></a> ... Goes to eventDetails.php, and transfer/displays the calID properly: <?php include('include/myConn.php'); include('include/myNav.php'); $calID = $_REQUEST['calID']; $query=mysql_query("select * from calTbl where calID = $calID") or die("Could not get data from db: ".mysql_error()); while($result=mysql_fetch_array($query)) { $calName=$result['calName']; $calDesc=$result['calDesc']; $calDate=$result['calDate']; $calID=$result['calID']; } ?> ... <a href="?calID=<?php echo $calID; ?>" onclick="openSesame();" class="myBold">Print</a> ... However, when I click the "Print" link (I see it is properly writing the calID on the link - like eventDetailsPrint.php?calID=7. The "eventDetailsPrint.php" is written from a JavaScript file as a new window function), it is coming up blank. <?php include('include/myConn.php'); //$calID = $_REQUEST['calID']; //$calID = $_SERVER['calID']; //$calID = echo $_GET['calID']; echo $_POST["calID"]; $query=mysql_query("select * from calTbl where calID = calID") or die("Could not get data from db: ".mysql_error()); while($result=mysql_fetch_array($query)) { $calName=$result['calName']; $calDesc=$result['calDesc']; $calDate=$result['calDate']; $calID=$result['calID']; } ?> ... <?php echo $calID; ?> ... What is the trick to pass an ID from page to page to page? Thanks. Link to comment https://forums.phpfreaks.com/topic/234617-transfer-id-to-3rd-page/ Share on other sites More sharing options...
Fadion Posted April 25, 2011 Share Posted April 25, 2011 In the first code you've used $_REQUEST to get the ID, while in the second one, $_POST. A brief explanation of various superglobals: $_GET => Handles url variables. For ex in: eventDetails.php?calID=10, "calID" is a url variable with value "10". It would be accessed by: $_GET['calID']. $_POST => Handles form data. You can't access any actual property without submitting a form first. Not use in your case. $_REQUEST => Handles $_GET, $_POST and $_COOKIE (cookies) data. Don't ever use it! It's a bad programming practice and can create security issues. So, in you case you will need $_GET to access the url variable. In the first script, replace: $calID = $_REQUEST['calID']; with: $calID = $_GET['calID']; While in the second one, replace: echo $_POST["calID"] with: $calID = $_GET['calID']; echo $calID; //just to confirm the variable has the correct value Link to comment https://forums.phpfreaks.com/topic/234617-transfer-id-to-3rd-page/#findComment-1205713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.