Dominic Mina Dominic Mina - 1 year ago 66
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>
<p class="post-info right">
<div class="post-box">
<div class="post-content">
<div class="post-intro">
<div class="post-footer clearfix">
<div class="continue-reading">

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

In news.php have to select from mysql all but only the table with the ID from index.php

$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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download