Passing value from href into PHP function
Results 1 to 3 of 3

Thread: Passing value from href into PHP function

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    1

    Passing value from href into PHP function

    Hi all,

    Currently, I work with 3 files: tour.html, menu.php & tour.php.

    From menu.php
    PHP Code:
    <li><a href="tour.html" class="parent_menu">Tour</a>
            <
    ul>
                <
    li><a href="tour.php?reg=North">North</a></li>
                <
    li><a href="tour.php?reg=Middle">Middle</a></li>
                <
    li><a href="tour.php?reg=South">South</a></li>
            </
    ul>
    </
    li
    From tour.php
    PHP Code:
    <?php
        $con 
    mysql_connect("localhost","...","...");
        if(!
    $con) {
            echo 
    "Could not connect: " mysql_error();
          }
            
        if(isset(
    $_GET['reg'])){
            
    $region $_GET['reg'];    
        }

        function 
    display($region
        {
            
    $result mysql_query('Select * From tour Where regionID="'.$region.'"');
            
            echo 
    '<div id="title-text">'.$region.'</div>';
            
            while(
    $record mysql_fetch_array($result))
            {        
                ...
            }
        }
        
    mysql_close($con);
    ?>
    My HTML File
    HTML Code:
    <body>
    ...
    <div id="topnav">
    	<?php include("menu.php") ?>
    </div>
    			
    <div id="left-top">
            <?php include("search_tool.php"); ?>
    </div>
    	
    <div id="right-top">
            <?php 
                	include("tour.php"); 
                	display();
            ?>
    </div>
    </body>
    I mean when users click a link from Tour (has 3 items), it will pass value of its item into tour.php to get $region. Then in the body (<div id="right-top">), it will display records by using function display(). But right now, when I click a href link, it displays nothing. So is there any way to differentiate a selection (of href) from users, and then pass it into body?

    Thank you all

  2. #2
    Beware: Crazy Scientist leatherback's Avatar
    Join Date
    Mar 2002
    Location
    Small border town between Netherlands and Germany
    Posts
    5,395
    What you have here should work. If you get no results, something else must be wrong. Set your PhP error reporting to max, so you get some error message. See also http://www.bio-vision.nl/coding/getsyntax

    Be carefull with this setup though. Using data that has been submitted by a user without verifying it, will eventually result in an unsecure website. Rather check the data first and/or run it through a cleaner function.

    In your case, a symple check would be:

    PHP Code:
    $valid = array(norteastsouthwest);

    $region "";

    if(
    in_array($_GET['reg'], $valid))
      {
      
    $region $_GET['reg'];    
      }

    // etc 
    Last edited by leatherback; 04-09-2012 at 07:21 AM.
    Php 4.* to 5.*. A small step for programmers. But a leap for me!

  3. #3
    Syntax Error
    Join Date
    Feb 2003
    Location
    San Diego, CA
    Posts
    443
    You are calling display() function without specifying $region

    Also I'm curious about where you link to tour.php but also specify "My HTML file" with an include of tour.php. Shouldn't you be linking to the HTML file?
    Last edited by m@tt; 04-09-2012 at 04:01 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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