Jump to content

Passing variables through URL


Schlo_50

Recommended Posts

Can anybody help me in developing my sscript to pass variables through a URL?

 

I have results echo'ed out onto a page and they are assigned a unique ID. When a link is clicked i want my display.php page to show all information about the link that was clicked. At the moment i have the categoryid at the end of my URL but when it links to display.php nothing but a blank screen is shown. Any ideas?

 

function:

function view($id){

$lines = file("usercats.txt");
  foreach ($lines as $line) { 
$data[$key] = explode("|", $line);

$user = trim($Data[$Key][0]);
	$catname = trim($Data[$Key][1]);
$id = trim($Data[$Key][2]);
$_SESSION['id'] = $id;
    


print '<a href="display.php?id='.$_SESSION['id'].'">$catname</a><br />';


}
   }

 

display.php

 

<?php
if(isset($_GET['id'])){
$id = (int) $_GET['id']; //type casting - only want integers for our ID. This would prevent any SQL injection attack
}else{
echo 'The Category information could not be found!';
exit;
}
$file = file("usercats.txt");

foreach($file as $Key => $Val){
$Data[$Key] = explode("|", $Val);
$loop_id = $Data[$Key][1];
if($loop_id == $id){//each time the loop runs, check if it is the ID we are looking for if it is display the info
	$username = $Data[$Key][0];
	$thumbid = $Data[$Key][2];
	$title = $Data[$Key][3];
	$desc = $Data[$Key][4];
	$date = $Data[$Key][5];
	//print out the information
	print $username;
	print $loop_id;
	print $thumbid;
	print $title;
	print $desc;
	print $date;
	break;//once found, we can exit out of our foreach loop
}
}

?>

 

 

Thanks for any help, suggestions, code snippets or tutorials!

 

Link to comment
https://forums.phpfreaks.com/topic/79958-passing-variables-through-url/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.