473,383 Members | 1,863 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,383 software developers and data experts.

Trying to make a simple book catalog

Hi!
I'm a librarian with a little PHP knowledge.. I'm trying to make a
catalog from scratch for my library. I don't like the look of the
current catalog so I'm trying to make a custom PHP/MySQL
implementation.

I can do everything I need to do except, I don't completely understand
a detail. Ideally I could write this:

<a href="catalogrecord.php?recordnum=4">Tom Sawyer</a>

The idea would be to pass the number 4 to the catalogrecord.php page
when the hyperlink is clicked. Then it would know which number in the
catalog it should pull up and display on the next page. Is this
possible? And if so, how could I access the recordnum=4 on the next
php file?

Will

Feb 21 '07 #1
11 3563
Yes, it is possible. There look for $_GET["recordnum"] in your
catalogrecord.php script.

On Feb 21, 10:20 am, fishmonger1...@gmail.com wrote:
Hi!
I'm a librarian with a little PHP knowledge.. I'm trying to make a
catalog from scratch for my library. I don't like the look of the
current catalog so I'm trying to make a custom PHP/MySQL
implementation.

I can do everything I need to do except, I don't completely understand
a detail. Ideally I could write this:

<a href="catalogrecord.php?recordnum=4">Tom Sawyer</a>

The idea would be to pass the number 4 to the catalogrecord.php page
when the hyperlink is clicked. Then it would know which number in the
catalog it should pull up and display on the next page. Is this
possible? And if so, how could I access the recordnum=4 on the next
php file?

Will

Feb 21 '07 #2
Rik
On Wed, 21 Feb 2007 02:20:49 +0100, <fi************@gmail.comwrote:
Hi!
I'm a librarian with a little PHP knowledge.. I'm trying to make a
catalog from scratch for my library. I don't like the look of the
current catalog so I'm trying to make a custom PHP/MySQL
implementation.

I can do everything I need to do except, I don't completely understand
a detail. Ideally I could write this:

<a href="catalogrecord.php?recordnum=4">Tom Sawyer</a>

The idea would be to pass the number 4 to the catalogrecord.php page
when the hyperlink is clicked. Then it would know which number in the
catalog it should pull up and display on the next page. Is this
possible? And if so, how could I access the recordnum=4 on the next
php file?
The question is a bit vague, but to get you started:

You say MySQL, so I assume that number 4 is an index in the database where
the records are stored? A list of links could be made by:

<?php
mysql_connect('hostname','username','password');//of you mysql db
mysql_select_db('catalogue');
$books = mysql_query('SELECT `id`, `name` FROM `book`');
while($book = mysql_fetch_assoc($books)){
print '<a
href="catalogrecord.php?recordnum='.$book['id'].'">'.$book['name'].'</a><br>';
}
?>

And the receiving script would do something like this:

<?php
$book_id = intval($_GET['recordnum']);
mysql_connect('hostname','username','password');//of you mysql db
mysql_select_db('catalogue');
$bookresult = mysql_query('SELECT * FROM `book` WHERE `id` = '.$book_id);
if(mysql_num_rows($bookresult) 0){
$book = mysql_fetch_assoc($bookresult);
foreach($book as $key =$value){
print $key.':'.$value.'<br>';
}
} else {
echo 'Book not found in database.';
}
?>

--
Rik Wasmus
Feb 21 '07 #3
"Klarth" <ka*****@gmail.comwrites:
Yes, it is possible. There look for $_GET["recordnum"] in your
catalogrecord.php script.
Could someone explain to a noob the use of _get here and why not _post?
Feb 21 '07 #4
Richard wrote:
"Klarth" <ka*****@gmail.comwrites:
>Yes, it is possible. There look for $_GET["recordnum"] in your
catalogrecord.php script.

Could someone explain to a noob the use of _get here and why not _post?
Because he's passing it as part of the URL, so it's a GET request. A
POST request would come from a form with method=post.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 21 '07 #5
Richard wrote:
"Klarth" <ka*****@gmail.comwrites:
>Yes, it is possible. There look for $_GET["recordnum"] in your
catalogrecord.php script.

Could someone explain to a noob the use of _get here and why not _post?
Oops - pressed send too quickly.

When the POST method is used, the parameters are not passed in the link
as part of the query string; rather they are passed by the browser out
of sight of the user.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 21 '07 #6
Rik
On Wed, 21 Feb 2007 03:59:56 +0100, Jerry Stuckle
<js*******@attglobal.netwrote:
Richard wrote:
>"Klarth" <ka*****@gmail.comwrites:
>>Yes, it is possible. There look for $_GET["recordnum"] in your
catalogrecord.php script.
Could someone explain to a noob the use of _get here and why not _post?

Oops - pressed send too quickly.

When the POST method is used, the parameters are not passed in the link
as part of the query string; rather they are passed by the browser out
of sight of the user.
Which on an 'open' site (this particular project seems to be local) would
have the advantage of being both bookmarkable (hmmmz, something doesn't
feel right about that word) and indexable by a search-engine.

--
Rik Wasmus
Feb 21 '07 #7
Rik wrote:
On Wed, 21 Feb 2007 03:59:56 +0100, Jerry Stuckle
<js*******@attglobal.netwrote:
>Richard wrote:
>>"Klarth" <ka*****@gmail.comwrites:

Yes, it is possible. There look for $_GET["recordnum"] in your
catalogrecord.php script.
Could someone explain to a noob the use of _get here and why not _post?

Oops - pressed send too quickly.

When the POST method is used, the parameters are not passed in the
link as part of the query string; rather they are passed by the
browser out of sight of the user.

Which on an 'open' site (this particular project seems to be local)
would have the advantage of being both bookmarkable (hmmmz, something
doesn't feel right about that word) and indexable by a search-engine.

--Rik Wasmus
Groan, Rik - was that on purpose? :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 21 '07 #8
>
And the receiving script would do something like this:

<?php
$book_id = intval($_GET['recordnum']);
mysql_connect('hostname','username','password') ;//of you mysql db
mysql_select_db('catalogue');
$bookresult = mysql_query('SELECT * FROM `book` WHERE `id` =
'.$book_id);
if(mysql_num_rows($bookresult) 0){
$book = mysql_fetch_assoc($bookresult);
foreach($book as $key =$value){
print $key.':'.$value.'<br>';
}
} else {
echo 'Book not found in database.';
}
?>
Ask why
$book_id = intval($_GET['recordnum']);
is used early on in the script and is it there just to 'keep things
tidy'? What naughty things could happen if it was just
$book_id = $_GET['recordnum'];

Supplementary question: What would you do here if you were getting a
string instead of a number to use in your SQL?

Another supplementary question: Why would it be a _bad_ idea to 'be
helpful' with the 'not found' message by echoing back the input as
follows:
$recno = GET['recordnum'];
print("Sorry we could not find your request for $recno");
--
PETER FOX Not the same since the submarine business went under
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Feb 21 '07 #9
Rik
Peter Fox <pe******@eminent.demon.co.uk.not.this.bit.no.html wrote:
>And the receiving script would do something like this:

<?php
$book_id = intval($_GET['recordnum']);
>$bookresult = mysql_query('SELECT * FROM `book` WHERE `id` =
'.$book_id);
if(mysql_num_rows($bookresult) 0){
$book = mysql_fetch_assoc($bookresult);
//
> }
} else {
echo 'Book not found in database.';
}
?>

Ask why
$book_id = intval($_GET['recordnum']);
is used early on in the script and is it there just to 'keep things
tidy'? What naughty things could happen if it was just
$book_id = $_GET['recordnum'];
Google SQL injection.
Supplementary question: What would you do here if you were getting a
string instead of a number to use in your SQL?
If possible prepared statements, else mysql_real_escape_string();
Another supplementary question: Why would it be a _bad_ idea to 'be
helpful' with the 'not found' message by echoing back the input as
follows:
$recno = GET['recordnum'];
print("Sorry we could not find your request for $recno");
Because it could containt evil code. I think you know the answers to these
already :P. It's far beyond the scope of the question to go in great
detail about security and database handling, as it was local, I was only
offering a starting point.
--
Rik Wasmus
Feb 21 '07 #10
Rik
Hmmmz, it was indeed very late, because this was still in the outbox this
morning:

Jerry Stuckle <js*******@attglobal.netwrote:
Rik wrote:
>>When the POST method is used, the parameters are not passed in the
link as part of the query string; rather they are passed by the
browser out of sight of the user.

Which on an 'open' site (this particular project seems to be local)
would have the advantage of being both bookmarkable (hmmmz, something
doesn't feel right about that word) and indexable by a search-engine.

Groan, Rik - was that on purpose? :-)
Hmmmz, it's very, very late. I'd swear I was typing something about GET
before it.... Offcourse the advantages I mentioned are of a GET request :P.

Off to bed now, before I squander my credibility any further...
--
Rik Wasmus
Feb 21 '07 #11
Following on from Rik's message. . .
>
Because it could containt evil code. I think you know the answers to these
already :P. It's far beyond the scope of the question to go in great
detail about security and database handling, as it was local, I was only
offering a starting point.
Sorry Rik I didn't mean to question your code, in fact the very opposite
- A very good starting point it is too. An excellent and concise
starting point for three important questions everyone should know the
answers to.

--
PETER FOX Not the same since the submarine business went under
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Feb 21 '07 #12

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

Similar topics

3
by: christof hoeke | last post by:
hi, does anyone know about this book which sounds great? unfortunately i could not find anything more about it apart from the following entry at amazon (germany only, strange...) ...
1
by: Larry | last post by:
I am a C++/Java programmer trying to get going with some simpe xml transformations at work here. I bought the O'Reilly book Learning xlst for kicks. Someone at work sent me this xml shown below,...
2
by: DonMiche | last post by:
I'm having trouble producing an xml output from another xml file using xsl. The proper values are output to the browser as text with no formating or xml tags (<rowset> and <row>). Any ideas? ...
6
by: nemo | last post by:
Hi, I'm looking for a good introductory book on ASP.Net for teaching undergraduates who know VB.Net but are not programmers as such. Last year I used "Programming ASP.Net" - second edition, by...
1
momotaro
by: momotaro | last post by:
You are to write a card catalog type definition. There are up to 1000 books, and for each one you need: Title A list of up to 5 authors Catalog number A list of up to 5 subject headings Status...
1
by: Paw64 | last post by:
The book code would uniquely identify a book in a book catalog. The book code is a ten digits value, where the first nine digits must be decimal digits (0...9), and the tenth can be either a decimal...
4
by: =?Utf-8?B?VGVycmFuY2U=?= | last post by:
I have an application that runs fine on my machine(of course) that access the local Sql Server. However, when trying to run this application from another machine I receive a Sql timeout error. I...
15
by: dhr | last post by:
newbie question: Is there a 'K&R" type of Python book? The book that you'd better have on your shelf if you are going into Python?
5
by: Phil Hunt | last post by:
What is the significance of and @ prefix of a string. I see it mostly used in a SQL statement . Thanks
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.