Results 1 to 13 of 13
  1. #1
    Newbie
    Join Date
    April 24th, 2005
    Posts
    14
    troubles with the $_GET['id'] funtion
    http://www.mysite.com/product.php?id=415027

    how can i get the id number above and display things from the database for the item matching that id number?

  2. #2
    ABW Ambassador
    Join Date
    January 18th, 2005
    Posts
    551
    $ThisID = $_GET['id'];
    $query = "SELECT stuff,more_stuff FROM table WHERE item='$ThisID'";
    $result = mysql_query($query);
    $row = mysql_fetch_array($result);

    echo $row['stuff'];
    echo $row['more_stuff'];

  3. #3
    Not Verif-Lidated infoTim's Avatar
    Join Date
    January 18th, 2005
    Location
    Sunny Florida
    Posts
    1,021
    One good thing to do is to use

    $ThisID = intval($_GET['id']);

    to prevent people from injecting junk into your SQL query and doing naughty things to your web site. That assures you have a clean number (or a zero).

    - Tim
    Tim
    consultant by day, affiliate by night

  4. #4
    Newbie
    Join Date
    April 24th, 2005
    Posts
    14
    thanx for replying but when i used the above code it gives me the following error for the line: $row = mysql_fetch_array($result);

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
    what could be wrong?

  5. #5
    Animal Lover
    Join Date
    January 18th, 2005
    Location
    oz
    Posts
    1,210
    Are you just copying the whole code provided and expecting it to work?

    Did you substitute the 'example' variables that Wayder provided to suit your table, and all the variables you want to display?

    Usually when that error displays it means that there's no query result and you haven't defined the variables correctly in the query statement.

    That was a good tip infospongellc - I'll remember to include that in my coding in future.

    Oscar

  6. #6
    ABW Ambassador
    Join Date
    January 18th, 2005
    Posts
    551
    The following line will probably be where your error is

    $query = "SELECT stuff,more_stuff FROM table WHERE item='$ThisID'";

    The best way for us to find out is if you post your code so that we can see what you have done.

    Two resources that will help you are

    http://www.php.net
    http://www.mysql.com

  7. #7
    Newbie
    Join Date
    April 24th, 2005
    Posts
    14
    here is my code...
    <?php
    mysql_connect('localhost','runsigne_main','mypass');
    mysql_select_db('runsigne_wtelectronics');
    $ThisID = intval($_GET['id']);
    $query = "SELECT Large Image, Long Description FROM products WHERE Product SKU='$ThisID'";
    $result = mysql_query($query);
    $row = mysql_fetch_array($result);

    echo $row['Large Image'];
    echo $row['Long Description'];
    ?>

  8. #8
    Not Verif-Lidated infoTim's Avatar
    Join Date
    January 18th, 2005
    Location
    Sunny Florida
    Posts
    1,021
    Your database column names have spaces in them?

    - Tim
    Tim
    consultant by day, affiliate by night

  9. #9
    Newbie
    Join Date
    April 24th, 2005
    Posts
    14
    ya, they do

  10. #10
    Animal Lover
    Join Date
    January 18th, 2005
    Location
    oz
    Posts
    1,210
    I was always of the impression that most programs will not support the spaces in column names and if you want to retain them, you need to replace them with underscores ie Large_Image. I normally get rid of spaces altogether ie LargeImage.

    Otherwise I think you have to use the little backtick thing (left of the 1 key on your keyboard) ie

    "SELECT `Large Image`,`Long Description` FROM products WHERE `Product SKU`='$ThisID'";

    Oscar

  11. #11
    ABW Ambassador
    Join Date
    January 18th, 2005
    Posts
    551
    I've always used large_image, long_description and product_sku and I have never experimented with spaces in database columns so never had this issue.

    I figure that you will need to use quotes of some sort or lose the space.

    http://dev.mysql.com/doc/mysql/en/legal-names.html

  12. #12
    Not Verif-Lidated infoTim's Avatar
    Join Date
    January 18th, 2005
    Location
    Sunny Florida
    Posts
    1,021
    I would think the spaces would be a real PITA on many levels. Probably not a good idea to use them...
    Tim
    consultant by day, affiliate by night

  13. #13
    Newbie
    Join Date
    April 24th, 2005
    Posts
    14
    i finally figured it out...the problem wasn't in my code but in the the datafeeds supplied by the company. they had multiple entries for the same product and therefore when trying to pull the information for one product it returned the above mentioned error.

    thanx for all the help though! and infospongellc, thanx for helping to make my script more secure i'll have to use that on all my sites!

    -Kyle

  14. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Troubles with LinkSynergy Interface?
    By tn-morgen in forum Rakuten LinkShare - LS
    Replies: 0
    Last Post: April 7th, 2008, 12:41 AM
  2. How The Heck? ReWritten Pages and $_GET Variables
    By Uncle Rico in forum Programming / Datafeeds / Tools
    Replies: 21
    Last Post: October 24th, 2007, 11:04 PM
  3. eBay Affiliate Troubles.
    By onemancreative in forum Commission Junction - CJ
    Replies: 14
    Last Post: June 28th, 2005, 04:45 PM
  4. Balance troubles
    By GregUK in forum ShareASale - SAS
    Replies: 1
    Last Post: June 24th, 2003, 02:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •