Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

phpCodeGenie error

Status
Not open for further replies.

mrsbean

Technical User
Jul 14, 2004
203
US
I used phpCodeGenie to generate some php code to work with a MySQL database. Mostly, I just want to learn php, so the goal is to pick apart what it generates and learn from dissecting it. I have had trouble finding a resource which knows anything about phpCodeGenie ... it's not that sophisticated, but what do you want for free?

I get a series of errors on a page which lists all of the entries in a table:

Notice: Undefined index: startLimit in c:\inetpub\ on line 9

Notice: Undefined index: rows in c:\inetpub\ on line 10

Notice: Undefined index: sortBy in c:\inetpub\ on line 11

Notice: Undefined index: sortOrder in c:\inetpub\ on line 12

Notice: Undefined variable: orderByQuery in c:\inetpub\ on line 39


Notice: Undefined index: startLimit in c:\inetpub\ on line 61

... Then I get the output as expected ...

Notice: Undefined index: startLimit in c:\inetpub\ on line 129


Thanks in advance,

Linda

**************************

Here's the code:
Code:
<?php
include_once("../common/dbConnection.php");
include_once("../common/header.php");
?>
<?
$initStartLimit = 0;
$limitPerPage = 10;

$startLimit = $_REQUEST['startLimit'];
$numberOfRows = $_REQUEST['rows'];
$sortBy = $_REQUEST['sortBy'];
$sortOrder = $_REQUEST['sortOrder'];

if ($startLimit=="")
{
                $startLimit = $initStartLimit;
}

if ($numberOfRows=="")
{
                $numberOfRows = $limitPerPage;
}

if ($sortOrder=="")
{
                $sortOrder  = "DESC";
}
if ($sortOrder == "DESC") { $newSortOrder = "ASC"; } else  { $newSortOrder = "DESC"; }
$limitQuery = " LIMIT ".$startLimit.",".$numberOfRows;
$nextStartLimit = $startLimit + $limitPerPage;
$previousStartLimit = $startLimit - $limitPerPage;

if ($sortBy!="")
{
                $orderByQuery = " ORDER BY ".$sortBy." ".$sortOrder;
}


$sql = "SELECT   * FROM MM_Hours".$orderByQuery.$limitQuery;
$result = MYSQL_QUERY($sql);
$numberOfRows = MYSQL_NUM_ROWS($result);


?>
<?
if ($numberOfRows==0) {  
?>

Sorry. No records found !!

<?
}
else if ($numberOfRows>0) {

        $i=0;
?>


<br>
<?
if ($_REQUEST['startLimit'] != "")
{
?>

<a href="<? echo  $_SERVER['PHP_SELF']; ?>?startLimit=<? echo $previousStartLimit; ?>&limitPerPage=<? echo $limitPerPage; ?>&sortBy=<? echo $sortBy; ?>&sortOrder=<? echo $sortOrder; ?>">Previous <? echo $limitPerPage; ?> Results</a>....
<? } ?>
<?
if ($numberOfRows == $limitPerPage)
{
?>
<a href="<? echo $_SERVER['PHP_SELF']; ?>?startLimit=<? echo $nextStartLimit; ?>&limitPerPage=<? echo $limitPerPage; ?>&sortBy=<? echo $sortBy; ?>&sortOrder=<? echo $sortOrder; ?>">Next <? echo $limitPerPage; ?> Results</a>
<? } ?>

<br><br>
<TABLE CELLSPACING="0" CELLPADDING="3" BORDER="0" WIDTH="100%">
        <TR>
                <TD>
                        <a href="<? echo $PHP_SELF; ?>?sortBy=KeyID&sortOrder=<? echo $newSortOrder; ?>&startLimit=<? echo $startLimit; ?>&rows=<? echo $limitPerPage; ?>">
                                <B>KeyID</B>
                        </a>
</TD>
                <TD>
                        <a href="<? echo $PHP_SELF; ?>?sortBy=Date&sortOrder=<? echo $newSortOrder; ?>&startLimit=<? echo $startLimit; ?>&rows=<? echo $limitPerPage; ?>">
                                <B>Date</B>
                        </a>
</TD>
                <TD>
                        <a href="<? echo $PHP_SELF; ?>?sortBy=Accomplishments&sortOrder=<? echo $newSortOrder; ?>&startLimit=<? echo $startLimit; ?>&rows=<? echo $limitPerPage; ?>">
                                <B>Accomplishments</B>
                        </a>
</TD>
                <TD>
                        <a href="<? echo $PHP_SELF; ?>?sortBy=Hours&sortOrder=<? echo $newSortOrder; ?>&startLimit=<? echo $startLimit; ?>&rows=<? echo $limitPerPage; ?>">
                                <B>Hours</B>
                        </a>
</TD>
        </TR>
<?
        while ($i<$numberOfRows)
        {

                if (($i%2)==0) { $bgColor = "#FFFFFF"; } else { $bgColor = "#C0C0C0"; }

        $thisKeyID = MYSQL_RESULT($result,$i,"KeyID");
        $thisDate = MYSQL_RESULT($result,$i,"Date");
        $thisAccomplishments = MYSQL_RESULT($result,$i,"Accomplishments");
        $thisHours = MYSQL_RESULT($result,$i,"Hours");

?>
        <TR BGCOLOR="<? echo $bgColor; ?>">
                <TD><? echo $thisKeyID; ?></TD>
                <TD><? echo $thisDate; ?></TD>
                <TD><? echo $thisAccomplishments; ?></TD>
                <TD><? echo $thisHours; ?></TD>
        <TD><a href="editMM_Hours.php?KeyIDField=<? echo $thisKeyID; ?>">Edit</a></TD>
        <TD><a href="confirmDeleteMM_Hours.php?KeyIDField=<? echo $thisKeyID; ?>">Delete</a></TD>
        </TR>
<?
                $i++;

        } // end while loop
?>
</TABLE>


<br>
<?

if ($_REQUEST['startLimit'] != "")
{
?>

<a href="<? echo  $_SERVER['PHP_SELF']; ?>?startLimit=<? echo $previousStartLimit; ?>&limitPerPage=<? echo $limitPerPage; ?>&sortBy=<? echo $sortBy; ?>&sortOrder=<? echo $sortOrder; ?>">Previous <? echo $limitPerPage; ?> Results</a>....
<? } ?>
<?
if ($numberOfRows == $limitPerPage)
{
?>
<a href="<? echo $_SERVER['PHP_SELF']; ?>?startLimit=<? echo $nextStartLimit; ?>&limitPerPage=<? echo $limitPerPage; ?>&sortBy=<? echo $sortBy; ?>&sortOrder=<? echo $sortOrder; ?>">Next <? echo $limitPerPage; ?> Results</a>
<? } ?>

<br><br>
<?
} // end of if numberOfRows > 0 
 ?>

<?php
include_once("../common/footer.php");
?>
 
You get a series of notices, not errors. It is not the same thing. Notices warn you about things that your code is attempting to do, but can't and that usually don't interfere with the functionality of the code. It is a good thing to get rid of them anyway. Yours are very self explanatory and easy. You are trying to read an index from an array that does not exist at that time. Look at the top of your code. You are assigning values to variables:
Code:
$startLimit = $_REQUEST['startLimit'];
$numberOfRows = $_REQUEST['rows'];
$sortBy = $_REQUEST['sortBy'];
$sortOrder = $_REQUEST['sortOrder'];
You are simply assuming that these variables exist in the $_REQUEST array. PHP is telling you that sometimes when the code is run, they don't. Use isset() when you want to check if the variables exist. If you do that, the notices will disappear.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top