473,320 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Passing variables (I think) ??

I have below a quite simple php page which queries a database table of all
records and outputs the result. However on this page I only output 3 of the
fields and I would like to click on a particular row which would then bring
up a detail page (which displays all the fields (perhaps 10 or more) of that
record).

Do I create another php file called detail.php which includes the line:
$sql = 'SELECT * FROM `link` WHERE link_id = $id;

and then alter the echo line below to something like:
echo "<TR><TD><a
href=detail.php?link_id=$id</TD><TD>$title</TD><TD>$description</TD></TR>";

which would then pass the variable $id into the sql statement in detail.php.
??

Any advice on the next steps would be welcome.

Cheers

Phil
<html>
<body>
<?php

// listrecords.php
// lists brief details of records (1 record per row)

$localhost = 'localhost';
$username = 'username';
$password = 'password';
$database = 'database';

$dbconnection = mysql_connect($localhost, $username, $password);
if (! $dbconnection)
{
die ("Couldn't connect to MySQL");
exit;
}

$db=mysql_select_db($database, $dbconnection);
if (!$db)
{
echo "Could not select database";
exit;
}

$sql = 'SELECT `link_id`,`title`,`description` FROM `links` LIMIT 0, 30';

$mysql_result=mysql_query($sql,$dbconnection);
$num_rows=mysql_num_rows($mysql_result);

if ($num_rows == 0) {
echo "Sorry, we have no records";
}
else
{

echo "<TABLE ALIGN=\"CENTER\" BORDER=\"1\">";
echo "<TR><TH>Record ID</TH><TH>Title</TH><TH>Description</TH></TR>";

while ($row=mysql_fetch_array($mysql_result))
{
$id=$row["link_id"];
$title=$row["title"];
$description=$row["description"];

echo "<TR><TD>$id</TD><TD>$title</TD><TD>$description</TD></TR>";

}
}
?>
</TABLE>
</body>
</html>
Jul 17 '05 #1
4 1351

Phil Latio wrote:
I have below a quite simple php page which queries a database table of all records and outputs the result. However on this page I only output 3 of the fields and I would like to click on a particular row which would then bring up a detail page (which displays all the fields (perhaps 10 or more) of that record).

Do I create another php file called detail.php which includes the line:

yes, that is a way
$sql = 'SELECT * FROM `link` WHERE link_id = $id;
this is not so good, because:

1. if register_globals is off (which it should be), $link_id gets not
automatically registered. use $_GET['link_id']

2. $_GET['link_id'] is user submitted data, so never ever trust it.
validate. i suppose your id's are integers, so using
(int)$GET_['link_id'] forces anything that is sent into an integer,
which in the worst case is just 0.
and then alter the echo line below to something like:
echo "<TR><TD><a

href=detail.php?link_id=$id</TD><TD>$title</TD><TD>$description</TD></TR>";

yes, like that.

micha

Jul 17 '05 #2
> > $sql = 'SELECT * FROM `link` WHERE link_id = $id;

this is not so good, because:

1. if register_globals is off (which it should be), $link_id gets not
automatically registered. use $_GET['link_id']

2. $_GET['link_id'] is user submitted data, so never ever trust it.
validate. i suppose your id's are integers, so using
(int)$GET_['link_id'] forces anything that is sent into an integer,
which in the worst case is just 0.


Many thanks for replying.

Are you suggesting something along these lines?

$specific_link = (int)$_GET['link_id'];
$sql = 'SELECT * FROM `link` WHERE link_id = $specific_link;

Cheers

Phil
Jul 17 '05 #3

Phil Latio wrote:
$sql = 'SELECT * FROM `link` WHERE link_id = $id;


this is not so good, because:

1. if register_globals is off (which it should be), $link_id gets not automatically registered. use $_GET['link_id']

2. $_GET['link_id'] is user submitted data, so never ever trust it.
validate. i suppose your id's are integers, so using
(int)$GET_['link_id'] forces anything that is sent into an integer,
which in the worst case is just 0.


Many thanks for replying.

Are you suggesting something along these lines?

$specific_link = (int)$_GET['link_id'];
$sql = 'SELECT * FROM `link` WHERE link_id = $specific_link;

Cheers

Phil

yes.

general.php contains

<a href=detail.php?link_id=YOUR_INT_VALUE>link</a>

and detail.php copntains the above code.

micha

Jul 17 '05 #4
> yes.

general.php contains

<a href=detail.php?link_id=YOUR_INT_VALUE>link</a>

and detail.php copntains the above code.

micha


Thanks again.

Cheers

Phil
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: lawrence | last post by:
Those of you with backgrounds with the C language will laugh at my mistake, but those of you, like myself, who deal mostly with PHP should be warned about passing variables as references -...
7
by: Matthew Robinson | last post by:
i read a tutorial the other day on passing variables between php pages using a html form and setting the action to the php page to parse, can anybody see anything wrong with the code below? the...
2
by: Chieko Kuroda | last post by:
Hello all, I would like to learn the syntax for passing variables that I retreived from a database to a second asp page. Currently, I'm using: Response.Write "<tr><td>&nbsp;</td><td><Font size=...
1
by: Consuelo Guenther | last post by:
Hello, I am having problems with passing variables between pages. I have the following: First asp page has the function: -----------------------------------------------------------------------...
7
by: Khai | last post by:
First off, yes, I understand the crapload of tutorials out there, (well, rather, I understand there /are/ a crapload of tutorials out there), the problem is my comprehension. I'm trying to pass...
3
by: jsdeveloper | last post by:
Hi, I just started programming in javascript, and I'm having a problem passing variables between javascript and asp code in .asp page. Can you please help? I've given the sample code below. ...
1
satterfieldben
by: satterfieldben | last post by:
I have a newbie question about passing variables between functions. I am wanting to use a drop down box to select a value. Then base on which was selected, it would create a variable and I would call...
5
by: Shawn Northrop | last post by:
test.php: <?php $d=$_GET; echo $d; ?> when i go to www....com/test.php?data=1 nothing happens.
6
by: coool | last post by:
Hi :) anyone knows how can I send variables from a php page to a form - i need to fill the form with these variables ? maybe using (the process of passing variables to other pages - through...
6
BezerkRogue
by: BezerkRogue | last post by:
This is the most fundamental action I am sure, but I can't seem to make it happen. I am familiar with passing variables in ASP. But that doesn't seem to be the preferred method in .NET. I have...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.