Jump to content

Help on error-undefined index


gnawz

Recommended Posts

I have two files;

 

brandview.php  AND brandshow.php

 

brandview.php has a dynamic drop down form which a user selects to view results as per the selection in brandshow.php

 

 

The display should come with its editing properties....eg modify and delete

 

I however get the undefined index error and nothing is displayed.  Please help me.

 

My two files

 

brandview.php

<?php
require_once '../../functions.php';

$_SESSION['login_return_url'] = $_SERVER['REQUEST_URI'];
checkUser();

?> 

<body>
<form action="index.php?view=brandshow" method="post" name="frmShowBrand">
<table width="100%" border="0">
    <tr>
      <td width="100">View By brand:</td>
      <td width="200"><select name = "sltBrand" onChange="ShowBrand();">
            <option value="0">Select Brand</option>
            <?
		$sql = "SELECT DISTINCT Brand FROM cstockitems ORDER BY Brand ASC";
		$result = dbQuery($sql);		

		if(dbNumRows($result))
		{
			while($row1 = dbFetchAssoc($result))
			{
			echo "<option>$row1[brand]</option>";
			}
		}
		 		else 
				{
			echo "<option>No Brands Present</option>"; 
				}
  ?>
          </select></td>
    </tr>
  </table>
</form>
</body>
<script>
function ShowBrand()
{
window.location.href = 'index.php?view=brandshow';
}

</script>
?>

 

 

 

 

 

 

 

brandshow.php

 

<?
require_once '../../functions.php';

//error_reporting(0);
/*if (!defined('WEB_ROOT')) {
exit;
}*/

$ShowBrand = $_POST["sltBrand"];

$sql = "SELECT * FROM cstockitems WHERE Brand = '$ShowBrand'";
//$sql = "SELECT * FROM cstockitems GROUP BY Brand";
$rowsPerPage = 10;

$result     = dbQuery(getPagingQuery($sql, $rowsPerPage));
$pagingLink = getPagingLink($sql, $rowsPerPage);

?>
<form action="index.php?view=choice" method="post"  name="frmList" id="frmList">
  <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
    <tr align="center" class="title_text"> 
      <td width="400" class="">Brand</td>
<td width="400" class="">Category</td>
      <td width="400">Date Created </td>
      <td width="200">View</td>
      <td width="200">Modify</td>
    </tr>
    <?php
if (dbNumRows($result) > 0) {
	$i = 0;

	while($row = dbFetchAssoc($result)) {
	extract($row);

	if ($i%2) {
		$class = 'row1';
	} else {
		$class = 'row2';
	}
	$i += 1;
?>
    <tr class="<?php echo $class; ?>"> 
      <td width="400"><?php echo $Brand; ?></td>
<td width="400"><?php echo $Category; ?></td>
      <td width="400"><?php echo $DateAddedBrand; ?></td>
      <td width="200" align="center"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?view=detail&ProductID=<?php echo $ProductID; ?>">Details</a></td>
      <td width="200" align="center"><a href="javascript:modifyBrand(<?php echo $ProductID; ?>);">Modify</a></td>
    </tr>
    <?php
} // end while


?>
    <tr> 
      <td colspan="4" align="center"> 
        <?php 
   echo $pagingLink;
   ?>
      </td>
    </tr>
    <?php	
} else {
?>
    <tr> 
      <td colspan="4" align="center">No brands yet</td>
    </tr>
    <tr> 
      <td colspan="4" align="center"> </td>
    </tr>
    <?php
}
?>
    <tr> 
      <td colspan="4" align="right"> 
        <input name="AddBrand" type="submit" value="Add" class="button_image"> 
	<input type="submit" name="DeleteBrand" value="Delete" class="button_image">
    </tr>
  </table>
</form>

 

Link to comment
https://forums.phpfreaks.com/topic/119630-help-on-error-undefined-index/
Share on other sites

$_POST will show nothing because you are not actually "posting" the data.

 

Change your javascript from this:

window.location.href = 'index.php?view=brandshow';

 

To this:

document.getElementById('frmShowBrand').submit();

 

Then give your form tag an id attribute and set it to frmShowBrand.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.