Trying to select just the product I click on for next page

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
nutstretch
Forum Contributor
Posts: 104
Joined: Sun Jan 11, 2004 11:46 am
Location: Leicester

Trying to select just the product I click on for next page

Post by nutstretch »

I have a page which returns the results of a search and have added a link on the image displayed. I want this link to open another page where more info on that product is displayed. below is the code for the link and image.

print "<td><a href = 'search.php?id=$style'><img src='$test' width='128' height='85' alt='Click here to see more info on this shoe'></a></td>";

I have tested and the id works on this page.

I need to carry that ID over to the next page so do another query just on that ID.

How do I get that id to go across ? I have tried this:

$resultID = mysql_query("SELECT * FROM tblShoes where StyleID like '$style'", $linkID);

... but get told undefinded variable style

Am I supposed to declare and populate earlier or have I left some code out ?

Any help appreciated
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You are trying to get the value of style from the URL? If that's so then you need to use $_GET['id'] not $style.

Mac
nutstretch
Forum Contributor
Posts: 104
Joined: Sun Jan 11, 2004 11:46 am
Location: Leicester

Post by nutstretch »

I tried this: $style = $_GET['id']; and it didn't work.

I got

Warning: Undefined variable: _GET in c:\program files\apache group\apache\htdocs\newwebsite\search.php on line 51

i also tried this: $resultID = mysql_query("SELECT * FROM tblShoes where StyleID like '$_GET['id']'", $linkID);

and got this error

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\program files\apache group\apache\htdocs\newwebsite\search.php on line 52

i am feeling really thick today sorry!!!
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

What version of PHP are you running?
nutstretch
Forum Contributor
Posts: 104
Joined: Sun Jan 11, 2004 11:46 am
Location: Leicester

Post by nutstretch »

PHP4
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

PHP 4 what? There's a massive difference between 4.0 and 4.1 and up.

Mac
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

You are using an old version of PHP:

Code: Select all

$sql = "SELECT * FROM tblShoes where StyleID like '".$HTTP_GET_VARS['id']."'";

$resultID = mysql_query($sql, $linkID);
Mark
mahara
Forum Commoner
Posts: 37
Joined: Wed Nov 13, 2002 1:08 am
Location: Bandung, Jawa Barat, Indonesia

Post by mahara »

Straterra wrote:What version of PHP are you running?
According to statement above, your version of PHP may haven't supported yet superglobals variables starts with '$_' (eg: $_GET, $_POST, etc.) especially if you are running version below 4.1.0. Try to upgrade to 4.1.0 or later (eg: 4.3.4) first if you want to use those type of variables.
However, if you don't want to, you still can use '$HTTP_GET_VARS' or '$HTTP_POST_VARS'. But remember if you enclose this variable(s) within a function, you should globalize the variable(s) first using 'global' keyword.

Code: Select all

function whatever()
&#123;
   global $HTTP_GET_VARS;

   $style = $HTTP_GET_VARS&#1111;'id'];
&#125;
Hope helps. :)
nutstretch
Forum Contributor
Posts: 104
Joined: Sun Jan 11, 2004 11:46 am
Location: Leicester

Post by nutstretch »

many thanks. If I upgrade do I have to uninsally what I have and reconfigure. I seem to remember getting very confused when i set it up lol. :?
mahara
Forum Commoner
Posts: 37
Joined: Wed Nov 13, 2002 1:08 am
Location: Bandung, Jawa Barat, Indonesia

Post by mahara »

If you prefer to upgrade, you can read how configure your server and you PHP in 'install.txt' that included in the PHP distro files. Check it up and see how easy to install PHP.

Remember to restart your server after finishing the installation.

Hope helps.
Post Reply