variable not printing with GET statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
imimin
Forum Commoner
Posts: 38
Joined: Thu Oct 18, 2007 5:44 pm

variable not printing with GET statement

Post by imimin »

I have the following code on my index page that 'dynamically' creates a link to the prod_detail page (second set of code following):

Code: Select all

<A HREF=\"$sitelocation" . "$item_url" . "?" . "item_short_desc\">
I pass the code above to the code below (on another page) using the GET command:

Code: Select all

        
            <?php
            $item_short_desc = $_GET['item_short_desc'];
            //$name = $_GET['name'];
            
            echo($item_short_desc);
        ?>
but it doesn't seem to work? The pro_detail.php page opens, but '$item_short_desc' does not echo (print)??

In case you need to see it, I have the more of my index page listed below (where I get my 'item_short_desc' variable from):

Code: Select all

            <?php
    $total_items = "SELECT * FROM poj_products";
    $result = mysql_query($total_items);
    $number_of_rows=mysql_num_rows($result);
 
    ?>
 
    <?php
    if (isset($_POST['start_view'])) {
        $start_view = $_POST['start_view'];
    }else{
        $start_view = 0;
    }
    if (isset($_POST['previews_per_page'])){
        $items_to_view = $_POST['previews_per_page'];
    }else{
        $items_to_view = 12;
    }
    ?>
 
    <?php
    $num_pages = $number_of_rows/$items_to_view;
    $num_pages = ceil($num_pages);
    ?>
 
<?php
 
        $get_items = "SELECT * FROM poj_products LIMIT $start_view,$items_to_view";
        $get_items = mysql_query($get_items);
 
        echo "<CENTER>";
        echo "<TABLE WIDTH=\"90%\" CELLSPACING=\"10\">";
        echo "<TR>";
 
        $rowbreaks = 1;
        while($item_row = mysql_fetch_array($get_items)){
            $item_short_desc = $item_row['short_desc'];
            $item_url = $item_row['url'];
            $item_img = $item_row['img'];
            $item_prod_name = $item_row['prod_name'];
            $item_prod_code = $item_row['prod_code'];
            $item_retail = $item_row['retail'];
 
            //list($width, $height) = getimagesize($item_lnk);
 
            //if($width > 200){
            //
            //}else{
            //
            //}
 
            echo "<TD class=\"preview-images\" VALIGN=\"top\" WIDTH=\"25%\">
                  <CENTER><A HREF=\"$sitelocation" . "$item_url" . "?" . "item_short_desc\">
                  <IMG SRC=\"includes/img_resize3.php?src=$sitelocation$item_img&width=144&height=144&qua=50\" BORDER=\"0\"></A>
                  <b>$item_prod_name</b>
                  <HR></CENTER>
                  $item_short_desc
                  <BR><BR>
                  $item_prod_code
                  <BR>
                  <B>$item_retail</B></P>
                  <BR></TD>";
 
            if($rowbreaks == 4){
                echo "</TR><TR>";
                $rowbreaks = 0;
            }
 
            $rowbreaks++;
        }
 
        echo "</TR>";
        echo "</TABLE>";
        echo "</CENTER>";
 
    ?>
semlar
Forum Commoner
Posts: 61
Joined: Fri Feb 20, 2009 10:45 pm

Re: variable not printing with GET statement

Post by semlar »

It doesn't look like you're assigning a value to it, what do you want it to echo?

If your URL just contains file.php?item_short_desc, then $_GET['item_short_desc'] isn't going to contain any data.

You need something like file.php?item_short_desc=fubar.

You can also check if it's set even if it's blank by using isset($_GET['item_short_desc']).
Randwulf
Forum Commoner
Posts: 63
Joined: Wed Jan 07, 2009 7:07 am

Re: variable not printing with GET statement

Post by Randwulf »

What exactly is it that gets passed to the page? It's not actually the <A HREF=\"$sitelocation" . "$item_url" . "?" . "item_short_desc\"> is it?

Try entering this into your address bar and see what it says:

Code: Select all

http://www.sitenamehere/phpfi
lenamehere.php?item_short_desc=insert_som
e_witty_phrase_here
asparak
Forum Newbie
Posts: 13
Joined: Tue Feb 24, 2009 3:38 pm

Re: variable not printing with GET statement

Post by asparak »

Don't know if its gonna help you, but I got this to work on my simple setup today.

Index page contains <a href="index2.php?id=<?php echo $event->event_id; ?>">
index2.php contains $eventsql = "SELECT * FROM ".EVENT_TABLE." WHERE event_id = ".$_GET['id'];

Think it might give you something to look at.
Post Reply