Dominic Mina Dominic Mina - 2 months ago 8
MySQL Question

Get an id to another page

Hello is my frist post there, i need your help.

Frist at all, i want to say sorry for my bad english. I hope you will undestoode me :D

So, i'm a newbie in php and i got a problem.
I want to take the id from a file, to another file, but i don't know how. I will let you the codes.

while($array = $db->get_row($row))
{
$id = $array['id'];
$Nume = $array['user_name'];
$date = date("Y-m-d H:i:s", $array['date']);;
$stitle = $array['shorttext'];
$text = $array['text'];
$logs .= '
<div class="post">
<div class="post-meta clearfix">
<h4 class="post-title left">
<a href="/index.php?page=news id='.$id.'">'.$stitle.'</a>
</h4>
<p class="post-info right">
<span>'.$Nume.'</span>
'.$date.'
</p>
</div>
<div class="post-box">
<div class="post-content">
<div class="post-intro">
'.$text.'
</div>
</div>
<div class="post-footer clearfix">
<div class="continue-reading">
</div>
</div>
</div>
</div>
<br>
';
}


Here where is ID, i want to take that id to the news page. (the code is in index.php)
'.$stitle.'

In news.php have to select from mysql all but only the table with the ID from index.php
if(isset($_GET['id'])){

$id = (int)$_GET['id'];

$row = $db->sql("SELECT * FROM `ucp_news` WHERE `id` = '".$id."' ");
$array = $db->get_array($row);


Can you help me, please?

Answer

Your PHP code is correct, although you should be using htmlspecialchars() when adding the variables to the output. This to prevent XSS attacks, and the like.

Though, your problem lies most likely in this line:

<a href="/index.php?page=news id='.$id.'">

More specifically, the missing ampersand (&) between news and id. Try to look at the value of $_GET['page'] when clicking on the link, then you should see what the problem is.

Comments