Page 1 of 1

Passing values through the URL

Posted: Sun May 31, 2009 12:29 pm
by php_beginner_83
Hi

I'm trying to pass values between web pages using php and have come across a problem. On the first page, when a user clicks on the 'Photos' link, I want the photo albums to display in the content section of the page. To make sure the correct albums are displayed I want to pass a value to search the database where my photos are stored. The value I want to search the database on is passed from a previous web page. This value is $getValue.
Is the way I'm doing this wrong??

This is the code for this page..

Code: Select all

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<<?php 
$getValue = $_GET['place'];
?>
<title>My Travel Website</title>
<link href="americanStyle.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="wrapper">
    <div id="americaHeader">
             .........
    </div>
    
    <div id="menu">
        <ul>
            <li><a href="#">Home</a></li>
            <li><?php echo"<a href=America1.php?page=main>"; ?>Photos</a></li>
            <li><a href="#">Sights</a></li>
            <li><a href="#">Dos & Donts</a></li>
        </ul>
    </div>
 
    <div id="page">
        <div id="content">
                        
        <?php
            
 
                         $index = array( "main" => "DisplayAlbums.php?title=$getValue" , "photo" => "DatabaseConnectionBackup.php" ); 
 
                         if ( !empty( $_GET["page"] ) ) { 
                               $page = $_GET["page"]; 
 
                         if ( array_key_exists( $page , $index ) ) 
                               include( $index[$page] ); 
                          ?> 
                
        </div>  
    </div>
</div>
</body>
</html>

Re: Passing values through the URL

Posted: Sun May 31, 2009 12:57 pm
by kcormier
Couple problems. From what I can see in this code, there's nothing that will call this page that sets a value to $_GET['place'] unless that link is created somewhere else.

Also, you're using include wrong. Include doesn't work like viewing a webpage would. In other words you can't pass values to the included script like that. Read the documentation for include again and that should explain some stuff to you.

The last advice I have for you is to try to separate your logic from your html. Do all the php logic first all in one lump sum if you can. Then you have the html below and a minimal amount of php to insert your data into the script. It makes debugging your code MUCH easier.

-Kevin