Passing info in URL

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
therat
Forum Commoner
Posts: 62
Joined: Wed Oct 01, 2003 2:44 pm
Location: London

Passing info in URL

Post by therat »

I have the following 2 pages that i need to pass an id variable between. The first page lists all categories from a DB. The second should display all the sub-categories from the chosen main category. This is not happening at the moment.
Displays all categories

Code: Select all

<?php

switch($_GET['act']) {

    default:
    menu();
    break;

    case "sub":
    submit();
    break;

}

function menu() {
$skinz = my_conn();
$query_submit = "SELECT * FROM skinz_categories WHERE status='1' ORDER BY cat_name ASC";
$submit = mysql_query($query_submit, $skinz) or die(mysql_error());
$row_submit = mysql_fetch_assoc($submit);
$totalRows_submit = mysql_num_rows($submit);
	echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'>
  <tr>
    <td align='left' class='maintitle'>Choose A Category</td>
  </tr>
</table>
<table width='100%' cellspacing='0' class='tableborder'>
  <tr>
    <td width='95%' valign='top' class='post1'><table width='90%' border='1' align='center' cellpadding='0' cellspacing='0'>\n";
	do
	echo "<tr>
          <td class='heading'><a href='submit.php?act=sub&id=".$row_submit['cat_id']."'>".$row_submit['cat_name']."</a></td>
      </tr>
      <tr>
          <td>".$row_submit['cat_description']."</td>
      </tr>\n";
	while ($row_submit = mysql_fetch_assoc($submit));
	echo "</table></td>
  </tr>
</table>\n";
}

function submit() {
	include('sub.php');
}
?>
Displays all sub-categories in select list

Code: Select all

<?php
// Include SDK functions and files
require_once "forum/ipbsdk_class.inc.php";
$SDK =& new IPBSDK();

    // Logged in so retrieve member info
    $info = $SDK->get_info();
    $member_name = $info['name'];
    $member_id = $info['id'];

$id = $HTTP_GET_VARS['id'];
$skinz = my_conn();
$query_submit = "SELECT * FROM skinz_subcategories WHERE status='1' AND cat_id='$id'";
$submit = mysql_query($query_submit, $skinz) or die(mysql_error());
$row_submit = mysql_fetch_assoc($submit);
$totalRows_submit = mysql_num_rows($submit);
?>
<form action="upload.php" method="post" enctype="multipart/form-data">
<div align="center" class="tableborder">
<table width="95%" align="center" class="sborder">
    <tr>
        <td width="25%" class="statsheader">User Name :</td>
        <td width="75%" align="right" class="statsheader"><?php echo $member_name; ?></td>
   </tr>
   <tr>
        <td width="25%" class="statsheader">Sub Category :</td>
        <td width="75%" align="right" class="statsheader"><select name="select" class="forminput">
            <?php
do {  
?>
            <option value="<?php echo $row_submit['subcat_id']?>"><?php echo $row_submit['subcat_name']?></option>
            <?php
} while ($row_submit = mysql_fetch_assoc($submit));
  $rows = mysql_num_rows($submit);
  if($rows > 0) {
      mysql_data_seek($submit, 0);
	  $row_submit = mysql_fetch_assoc($submit);
  }
?>
          </select>
        </td>
    </tr>
</table>
</div>
</form>
Normally I would just use

Code: Select all

$id = $HTTP_GET_VARS['id'];
but this is not working. I assume this is because their are other things in the URL. How can I extract the ID from the URL.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

$id = $HTTP_GET_VARS['id']; should be fine, or even better $id = $_GET['id'] (or don't even create a temporary var $id, just use $_GET['id'] directly).
When you say it doesn't work, where is it failing? If you echo $_GET['id'] is it set ok? If you echo the query is that ok? Do you get any errors/warnings if you make error_reporting(E_ALL); the first line of the script?
therat
Forum Commoner
Posts: 62
Joined: Wed Oct 01, 2003 2:44 pm
Location: London

Post by therat »

Changed it to $_GET and works perfectly, thanks.
Post Reply