Page 1 of 1
Help with passing id and field info?
Posted: Fri Jul 03, 2009 7:12 pm
by imimin
Could someone please explain to me how to pass the id through a url so on the "receiving" page I can echo the data in the field of the id ?
Thank you!
Re: Help with passing id and field info?
Posted: Fri Jul 03, 2009 7:49 pm
by requinix
Code: Select all
<a href="page.php?id=123">Link</a>
Code: Select all
<?php // page.php
echo $_GET["id"]; // 123
Re: Help with passing id and field info?
Posted: Tue Jul 07, 2009 5:09 pm
by imimin
tasairis wrote:Code: Select all
<a href="page.php?id=123">Link</a>
Code: Select all
<?php // page.php
echo $_GET["id"]; // 123
How would you point to the correct field with this code?
Re: Help with passing id and field info?
Posted: Tue Jul 07, 2009 5:21 pm
by requinix
What field?
Re: Help with passing id and field info?
Posted: Tue Jul 07, 2009 5:33 pm
by imimin
Any field I want to specify.
Re: Help with passing id and field info?
Posted: Tue Jul 07, 2009 5:51 pm
by imimin
If I run this code like it is, it 's not pointing to a specific field, just a row, right? Or am I missing something?
Thanks for your help, just trying to learn.
Re: Help with passing id and field info?
Posted: Tue Jul 07, 2009 7:33 pm
by requinix
Nothing is pointing anywhere. $id is just a number - you do whatever you want with it.
Have you read through
the PHP manual recently?
Re: Help with passing id and field info?
Posted: Tue Jul 07, 2009 10:57 pm
by Skara
I think you're asking how an html form connects to php?
Code: Select all
<input type="text" name="somefield" />
when ^ is submitted, the url will be
file.php?somefield=what_you_type
Re: Help with passing id and field info?
Posted: Wed Jul 08, 2009 12:07 pm
by imimin
What I am trying to do is send the id of the product to the next page and in that page load the product description (desc). What I have so far is:
Code: Select all
<?php
$cat = $_GET['cat'];
$get_items = "SELECT * FROM poj_products WHERE cat='$cat'";
$get_items = mysql_query($get_items);
echo '<a href="'.$sitelocation.$item_row['url'].'?item_desc='.$item_row['id'].'>view details/order</a>';
?>
but url link is not echoed???
Re: Help with passing id and field info?
Posted: Wed Jul 08, 2009 12:29 pm
by requinix
Where did you (not) get $item_row from?
Re: Help with passing id and field info?
Posted: Wed Jul 08, 2009 12:42 pm
by superdezign
imimin wrote:but url link is not echoed???
No echo at all? If so, then your code is never reaching that area.
If that's not what you mean, then you are not using mysql_query() correctly. The function mysql_query() performs a query which gives you a handle to the results of the query, not the results themselves. You must use that handle in order to retrieve your data. This can be done with mysql_fetch_*() functions, where * is "array", "assoc", "object", etc. The PHP manual should tell you all that you need to know in regards to how those functions work.
PHP does not magically create variables for you. $item_row needs to be initialized to have any value beyond NULL. I'm assuming that you are looking for this:
Code: Select all
$item_row = mysql_fetch_assoc($get_items);
Also, your code is vulnerable to SQL injection, as you do not validate $_GET['cat'] before putting it into your query. The user could input any value at all into a query variable, and you must account for that.