Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Links help....

  1. #1
    Join Date
    Apr 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Links help....

    Hi I'm a newbie here, I'm new to this, got a question here


    Normally we key in text in the empty text box to look for data, for example:

    <body>
    <form method="post" action="data.php">
    <input type="text" name="shoe_1">
    <input type="submit" value="Submit Data">
    </form>

    my "data.php" will connect to mySQL and search for category "shoe_1" for air jordan when I type in "air jordan" in the blanks and press Submit Data button.


    What if I want a normal link to do this? for example a simple links:

    <body>
    <a> Air Jordan </a>


    so when user clicks on Air Jordan, it will run my data.php to connect to mySQL and search category "shoe_1" for Air jordan.


    How do I do that? Any Idea?
    Please Help....

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You can't do it via POST, but you can via GET:
    Code:
    <a href="data.php?shoe_1=air&#37;20jordan">Air Jordan</a>
    GET is more appropriate here anyway... POST is, by convention, used only for requests that do something more permanent than generate a page.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Apr 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanx for the reply.

    Is the code for POST same as the GET? I've only changed the POST word into GET in my php file. but it won't work.

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I often use:
    Code:
    <a href="data.php?submit">Air Jordan</a>
    with post data on the other end:
    Code:
    <?php
    if (isset($_GET["submit"])) {
      //do something
      }
    ?>
    But, as Twey said for generating pages, GET would be best.

    I think using GET is better anyways, because it gives the user the ability to copy the url and use it later.
    - Mike

  5. #5
    Join Date
    Apr 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    what is the command should i put in to allow the text clicked to be auto recognize and match by the database and show details.

    for example:
    i created a webpage with:
    <a href="data.php" target="diffpage">Air Jordan.

    as the database exactly has a product name Air Jordan.

    thank you

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Is the code for POST same as the GET?
    Pretty much, yes.
    I've only changed the POST word into GET in my php file. but it won't work.
    It should do, I'd guess you've missed one. You can also use $_REQUEST, which checks both POST and GET data (and cookie data too).
    what is the command should i put in to allow the text clicked to be auto recognize and match by the database and show details.

    for example:
    i created a webpage with:
    <a href="data.php" target="diffpage">Air Jordan.

    as the database exactly has a product name Air Jordan.
    It doesn't work like that. You have to put the data in your URL, it won't be magically picked up.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Apr 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanx you guys for the replies, but sorry, I'm quite confused.

    OK, I'll provide more details about what I have.

    Example of items in my SQL:
    Shoe_ID-------Shoe_Name--------Shoe_Price
    101------------Air jordan1-----------100.00
    102------------Air jordan2-----------200.00
    103------------Air jordan3-----------300.00



    Example of my data.php file:
    <?php
    $Shoe_ID = $_POST['Shoe_z'];

    ..............and so on, there's no problem in my php cause it work




    Example of my html file:
    <body>
    <form method="post" action="data.php">
    <input type="text" name="Shoe_z">
    <input type="submit" value="Submit Data">
    </form>

    So when I enter "Air jordan1", and click Submit Data. It will show:

    Air jordan1 100.00

    It worked. But now instead of entering Air jordan1 and press Submit, I wanna use a link like:

    <a> Air Jordan </a>


    so when I click on the Air Jordan link, it will show:

    Air Jordan 100.00



    Hope this is clear enough. HAHA.
    Please help.

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Place the link like so:

    Code:
    <a href="data.php?Shoe_z=Air&#37;20jordan1">Air Jordan</a>
    Then change the php code from $_POST to $_GET like so:

    Code:
    <?php
    $Shoe_ID = $_GET['Shoe_z'];
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    Apr 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Quote Originally Posted by thetestingsite View Post
    Place the link like so:

    Code:
    <a href="data.php?Shoe_z=Air%20jordan1">Air Jordan</a>
    Hope this helps.


    What does the %20 mean?

  10. #10
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    It's just a space in the url, you could probably just put a simple space in between them, but not sure. I just did that as a precaution.
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

Bookmarks

Posting Permissions

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