473,785 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Display selected record that has been passed to URL

Ren
Hello all,

I have a page which can list all records from a table in my local database.

For each record that is displayed there is link next to it. When the link is
pressed another page opens up and the ID (automated primary key in my table)
of the record selected is passed to the URL.

So now the URL looks something like this:

http://localhost/Webpages/newpage.php?recordID=3

How do I display the details of the record that has been selected on this
new page?

Any help much appreciated!

Thanks
Ren
Mar 10 '06 #1
5 2308
Ren:

I'm not sure what you're looking for. Basically, your newpage.php will
use code similar to what you must have used on the first page you
describe - the one that lists the records. You will get your primary
key by looking at $_GET["recordID"] and assigning it to a variable
(like $id). Of course you will want to validate this value and make
sure it is an integer and nothing else (search for sql injection
attacks to see why).

Then, you will execute a select against your table like (SELECT * FROM
table WHERE recordID = $id) using the passed recordID. Use the
appropriate functions/syntax (these will differ if you are using PEAR
DB or native php functions, and depending on how you want to display
the data) to navigate through your result set and write out the data as
html.

HTH,
Josh

Mar 10 '06 #2
Ren
Thanks for the quick reply.

It sounds easy from what you have stated but I still can't seem to get it to
work.

I think it may be something to do with my select statement. Here is a
sample of the code.

$RID = $_GET['recordID'];

$query = "SELECT * FROM dvd WHERE id = '$RID'";
$result = mysql_query($qu ery);
print ("$result[title]");

Just to let you know that the table is called 'dvd' and 'id' and 'title' are
column names in my table.

I am just trying to display the 'title' of the selected record.

Thanks
Slack
Mar 10 '06 #3

Ren wrote:
Thanks for the quick reply.

It sounds easy from what you have stated but I still can't seem to get it to
work.

I think it may be something to do with my select statement. Here is a
sample of the code.

$RID = $_GET['recordID'];

$query = "SELECT * FROM dvd WHERE id = '$RID'";
$result = mysql_query($qu ery);
print ("$result[title]");

Just to let you know that the table is called 'dvd' and 'id' and 'title' are
column names in my table.

I am just trying to display the 'title' of the selected record.

Thanks
Slack


..........try this (change hostname, username, password, database_name
accordingly).

$RID = $_GET['recordID'];
$query = " SELECT * FROM dvd WHERE id = '$RID' ";

$dbcnx = @mysql_connect( "localhost" , "username", "password") ;
or die(mysql_error ());

if (!@mysql_select _db("database_n ame", $dbcnx)) die(mysql_error ());

if (!($result = @mysql_query($q uery, $dbcnx)) ) die(mysql_error ());

while($row = @mysql_fetch_ro w($result))
{
echo $row['title'];
echo "<br>";
}

if(!(mysql_clos e($dbcnx))) die(mysql_error ());
HTH,
Hemanth

Mar 10 '06 #4
Ren, I have written up an article on SQL Injections that you might want
to look at, too. A SQL Injection is caused when an end-user modifies
your input value and adds their own SQL to it (which could result in a
deleted DB table or worse). For this particular example you could do
something simple like

if(!is_numeric( $RID))
{
die("Invalid Input");
}

More information is here:
http://www.digitalpropulsion.org/blo...PHP_with_MySQL

Mar 11 '06 #5
Ren
Thanks Adam for the link.
Mar 11 '06 #6

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

Similar topics

8
1721
by: TNGgroup | last post by:
Hi, Question, I have a simple form and want to submit a selected value of a combo box. so my combo box is named "selectname" and my form has action="file.asp?" what do I have to put after the question mark ? Thx in advance Wim
0
4087
by: dotyet | last post by:
Hey All, I have a small problem. consider the following >db2 "create table ttt (mynum float, yournum double )" DB20000I The SQL command completed successfully. >db2 "describe table ttt" Column Type Type
17
2081
by: perryche | last post by:
I have 5records, e.g. Rc1, Rc2, Rc3..., when user open up a form, I want it to open to a particular record (say Rc3) then when user chooses the Record Selector , it will go to Rc2 and , it will go to Rc4. If I use Sort in the query, it is sorted alphabetically; if I do not sort, whatever is the latest record will be on top. Any help/insight will be appreciated. Perry
4
1992
by: cwoll | last post by:
I am runing this function to toggle buttens to display an "X" when they is selected, the butten is linked to a yes/no field. This function works good, the problem I am having is that when I make a new record the "X" from the last record I looked at are still there, but the bottens are not selected nether should they be. How do I clear every thing when creating a new record? Any help would be apprecated. Clarence Wollman Function...
2
7053
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs, input box for units of service, description of the service and each row has its own dropdown list of unit fees that apply. Each dynamically created row will return 3 values fee1_choice, fee1_unit and fee1_money. Note The above informaton is...
7
11061
by: =?Utf-8?B?SnVsaWEgQg==?= | last post by:
Hi all, this is a second post, so apologies, but I never had an answer to my first post (several weeks ago) and I really need some help. I'm using a .Net 2.0 Gridview which is populated using an ObjectDataSource which calls on a method in a class. This all works fine. The Gridview has a select button automatically generated. When the user presses this I want to be able to take the data from the selected record and use it. However...
21
7162
by: postman | last post by:
I have a subform which is bound to a query which will display records using an ID# supplied from a listbox in the parent form. That same subform is also used to create new records using the following code in a "New Record" commandbutton: DoCmd.GoToRecord , , acNewRec Both functions work fine. However, if I have a selected record displayed, and I click the "New Record" button, it does not move to a new record. It just stays on the...
21
11143
by: mukeshrasm | last post by:
Hi I am deleting records from database using checkbox. means only that record will be deleted from database which are selected in checkbox. and before deleting record I am displaying a message "Are you sure to delete the selected records" using javascript.and when user clicks OK, record is deleted. Here in message I want it should like "Are you sure to delete 5 records" if user selects 5 records. So how can I do this using javascript. ...
1
2422
by: angelicdevil | last post by:
i have listbox 1 which displays status , based on selection of status listbox 2 displays usernames. and based on username selected the textbox displays the email id. its working fine till displaying user names in listbox 2 based on selected of status in listbox. but its not displaying the emailid based on selection of usernames and when i click on search for users button its refreshs the page and shows the intial page also want the text box...
0
10346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10096
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.