Page 1 of 1

i need help with my PHP code.

Posted: Wed Nov 14, 2007 7:56 am
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.

Posted: Wed Nov 14, 2007 8:51 am
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?

Posted: Wed Nov 14, 2007 11:46 am
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.