Jump to content

Getting information about id in page


vinnie19

Recommended Posts

index.php

<html>
<head>
<title>Just a title</title>
<link rel="stylesheet" type="text/css" href="css\style.css">

<?php 
	include("include\inc_posts.php");
	$info = new posts;
?>

</head>

<body>
<div id="header">
	<?php include("include\inc_header.php")?>
</div>

<div id="menu">
	<?php include("include\inc_menu.php")?>
</div>

<div id="database">
	<p class="titel">Video</p>
	<?php $info->show_video_posts() ?>
	<br>
	<p class="titel">Games</p>
	<?php $info->show_games_posts() ?>			
</div>

</body>
</html>

 

post.php

 

<html>
<head>
<title>Just a title</title>
<link rel="stylesheet" type="text/css" href="css\style.css">


</head>

<body>
<div id="header">
	<?php include("include\inc_header.php")?>
</div>

<div id="menu">
	<?php include("include\inc_menu.php")?>
</div>

<div id="database">
	<p class="titel"><?php echo $rij['titel']; ?></p>
	<p> U heeft geselecteerd id <?php echo $rij['id']; ?></p>
	<p> Dit is <?php echo $rij['titel']; ?></p>
</div>

</body>
</html>

 

inc_posts.php

<?php

class posts
{
function show_video_posts(){
	$db= sqlite_open ("database\dvddb.sdb");
	$sql= "SELECT * FROM allposts WHERE category = 'video' ORDER BY id DESC LIMIT 10;";
	$result= sqlite_query($db, $sql);

	while ($rij = sqlite_fetch_array($result)){
		echo ("<a href=\"post.php?id=". $rij['id'] ."\">".$rij['id']."|".
			$rij['titel']."</a>".
			"<br>\n");
		}
	return $info;
}//einde functie show_video_posts

function show_games_posts(){
	$db= sqlite_open ("database\dvddb.sdb");
	$sql= "SELECT * FROM allposts WHERE category = 'games' ORDER BY id DESC LIMIT 10;";
	$result= sqlite_query($db, $sql);

	while ($rij = sqlite_fetch_array($result)){
		echo ($rij['id']."|".
			$rij['titel']."".
			"<br>\n");
		}
	return $info;
}//einde functie show_games_posts

function show_video(){
	$db= sqlite_open ("database\dvddb.sdb");
	$sql= "SELECT * FROM allposts WHERE category = 'video' ORDER BY id;";
	$result= sqlite_query($db, $sql);

	while ($rij = sqlite_fetch_array($result)){
		echo ($rij['id']."|".
			$rij['titel']."".
			"<br>\n");
		}
	return $info;
}//einde functie show_video

function show_games(){
	$db= sqlite_open ("database\dvddb.sdb");
	$sql= "SELECT * FROM allposts WHERE category = 'games' ORDER BY id;";
	$result= sqlite_query($db, $sql);
	while ($rij = sqlite_fetch_array($result)){
		echo ($rij['id']."|".
			$rij['titel']."".
			"<br>\n");
		}
	return $info;
}//einde functie show_games

}//einde class

?> 

 

The header and the menu contains nothing interesting

 

This is what i have now:

On the index you see this:

 

1|record 1

2|record 2

 

Now i want to click on the 1|record 1 and then go to post.php and get there the info about record 1

And if i click on 2|record 2 then go to post.php but then with info about record 2

 

How can i do this?

Link to comment
https://forums.phpfreaks.com/topic/151236-getting-information-about-id-in-page/
Share on other sites

Instead of:

<div id="database">
      <p class="titel"><?php echo $rij['titel']; ?></p>
      <p> U heeft geselecteerd id <?php echo $rij['id']; ?></p>
      <p> Dit is <?php echo $rij['titel']; ?></p>
   </div>

 

You'll need to run a query before that that pulls the data out of the database again based on the ID:

 

$id = mysql_real_escape_string($_GET['id]);
$query = "SELECT * FROM allposts WHERE id = $id"; 

 

Does that help?  So instead of $rij, your array would be the row you pull from the database based on the ID.

Look up SQL injection using your favourite search.  as far as I know SQLite doesn't have the same feature as mySQL in php.  As you are getting the id from a link it shouldn't be a problem, but that won't stop people from editing the URL manually to jeopodise your database.  You may want to create a function (or find one on the net) with a preg_match(REGEX) in it.

fixed it myself

 

it was only this code on post.php

 

<?php	
$db= sqlite_open ("database\dvddb.sdb");
$query= "SELECT * from allposts WHERE id=" . $_GET["id"];
$result= sqlite_query($db, $query) or die ("FOUT: " . sqlite_error());
?>

 

Wasnt that hard

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.