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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.