i need help with my PHP code.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chishake
Forum Newbie
Posts: 2
Joined: Wed Nov 14, 2007 7:18 am

i need help with my PHP code.

Post by chishake »

hello folks, i am building a website for my company but i am having problems passing a variable in a url into my my mysql select statement.
I have a page called products that display a list of products in a database. there is also a link at the end of each product that will take you to another page which displays the product detail for a particular product. for example
<a href = products.php?id = '$id'>product details</a>
where $id is the id of a product in the database. there are many products that means the id will depend on the product that is being selected.
now i dont know how to implement the SELECT * FROM Products WHERE id = ......
can anyone help me out [s]pls[/s] please.
i am really stuck
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

In order to "get" a variable from a url you can either use $_GET or $_REQUEST.

e.g.

Code: Select all

if(isset($_GET['id'])) $id=$_GET['id'];
Is this what you were stuck on?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Make sure to properly validate and sanitize any REQUEST data prior to hitting the DB with it.

For querystring variables, use $_GET. For form variables, use $_POST. More information can be found in the PHP manual. Specifically, look for Superglobal Arrays.
Post Reply