Jump to content

Undefined index error in lampp


IreneLing

Recommended Posts

Hi all.Here is a part of my scripts . When I run it with my hosting server it works very well , but when I run it in ubuntu lampp , it keeps giving me these errors:

 

Notice: Undefined index: txtFirstName in /opt/lampp/htdocs/EMC/customer-search.php  on line 123

Notice: Undefined index: txtLastName in /opt/lampp/htdocs/EMC/customer-search.php on line 123

Notice: Undefined index: txtCell in /opt/lampp/htdocs/EMC/customer-search.php on line 123

Notice: Undefined index: txtGroup in /opt/lampp/htdocs/EMC/customer-search.php on line 123

Notice: Undefined variable: id in /opt/lampp/htdocs/EMC/customer-search.php on line 247

Notice: Undefined index: Page in /opt/lampp/htdocs/EMC/customer-search.php on line 253

Notice: Undefined index: Page in /opt/lampp/htdocs/EMC/customer-search.php on line 254

 

 

Here is the code:

 


<html>

<body>

<form name="frmSearch" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>">
  <table width="599" border="1">
    <tr>
      <th>Keyword
      <input name="txtFirstName" type="text" id="txtFirstName" value="<?=$_GET["txtFirstName"];?>">
      <input name="txtLastName" type="text" id="txtLastName" value="<?=$_GET["txtLastName"];?>">
      <input name="txtCell" type="text" id="txtCell" value="<?=$_GET["txtCell"];?>">



<?

     $opselect="SELECT DISTINCT Custgroup FROM UserAddedRecord";

$result = mysql_query ($opselect);

while($nt=mysql_fetch_array($result))
{
?>
<option><?= $nt[Custgroup]?></option>";

<?
}
?>

</select>
      <input type="submit" value="Search">
    </tr>
  </table>
</form>
<?
if($_GET["txtFirstName"] != "" || $_GET["txtLastName"] != "" || $_GET["txtCell"] != "" || $_GET["txtGroup"] != "")
    {
    $objConnect = mysql_connect("localhost","root","") or die(mysql_error());
    $objDB = mysql_select_db("EMC");
    // Search By Name or Email
    $strSQL = "SELECT * FROM UserAddedRecord WHERE (FirstName LIKE '%".$_GET["txtFirstName"]."%' and LastName LIKE '%".$_GET["txtLastName"]."%' and Cell LIKE '%".$_GET["txtCell"]."%' and Custgroup LIKE '%".$_GET["txtGroup"]."%')";
    $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
    $Num_Rows = mysql_num_rows($objQuery);


    $Per_Page = 2;   // Per Page

    $Page = $_GET["Page"];
    if(!$_GET["Page"])
    {
        $Page=1;
    }

    $Prev_Page = $Page-1;
    $Next_Page = $Page+1;

    $Page_Start = (($Per_Page*$Page)-$Per_Page);
    if($Num_Rows<=$Per_Page)
    {
        $Num_Pages =1;
    }
    else if(($Num_Rows % $Per_Page)==0)
    {
        $Num_Pages =($Num_Rows/$Per_Page) ;
    }
    else
    {
        $Num_Pages =($Num_Rows/$Per_Page)+1;
        $Num_Pages = (int)$Num_Pages;
    }


    $strSQL .=" order  by id DESC LIMIT $Page_Start , $Per_Page";
    $objQuery  = mysql_query($strSQL);

    ?>
    <table width="600" border="1">
      <tr>
        <th width="50"> <div align="center">#</div></th>
        <th width="91"> <div align="center">CustomerID </div></th>
        <th width="98"> <div align="center">Name </div></th>
        <th width="198"> <div align="center">Email </div></th>
        <th width="97"> <div align="center">CountryCode </div></th>
        <th width="59"> <div align="center">Budget </div></th>
        <th width="71"> <div align="center">Used </div></th>
      </tr>
    <?
    while($objResult = mysql_fetch_array($objQuery))
    {
    ?>
      <tr>
        <td><div align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?=$objResult["id"];?>"></div></td>
        <td><div align="center"><?=$objResult["id"];?></div></td>
        <td><?=$objResult["FirstName"];?></td>
        <td><?=$objResult["LastName"];?></td>
        <td><div align="center"><?=$objResult["MobileCompany"];?></div></td>
        <td align="right"><?=$objResult["Cell"];?></td>
        <td align="right"><?=$objResult["Workphone"];?></td>
      </tr>
    <?
    }
    ?>
    </table>
    <br>
    Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
    <?
    if($Prev_Page)
    {
           if($_GET["txtFirstName"] == "")
                      {
        echo " <a href='$_SERVER[sCRIPT_NAME]?Page=$Prev_Page&txtLastName=$_GET[txtLastName]'><< Back</a> ";    
                      }

            else
                      {
        echo " <a href='$_SERVER[sCRIPT_NAME]?Page=$Prev_Page&txtFirstName=$_GET[txtFirstName]'><< Back</a> ";
                      }

    }

    for($i=1; $i<=$Num_Pages; $i++){
        if($i != $Page)
        {

            echo "[ <a href='$_SERVER[sCRIPT_NAME]?Page=$i&txtFirstName=$_GET[txtFirstName]'>$i</a> ]";    

        }
        else
        {
            echo "<b> $i </b>";
        }
    }
    if($Page!=$Num_Pages)
    {
              if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "" && $_GET["txtCell"] == "")
                           {
                echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtGroup=$_GET[txtGroup]'>Next>></a> ";
                           }
              else if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "")
                           {
                echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtCell=$_GET[txtCell]'>Next>></a> ";    
                           }
              else if($_GET["txtFirstName"] == "" )
                           {
            echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtLastName=$_GET[txtLastName]'>Next>></a> ";    
                           }
              else
                           {
                echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtFirstName=$_GET[txtFirstName]'>Next>></a> ";    }
                       }
    
    mysql_close($objConnect);


    }    

else
{

    $strSQL = "SELECT * FROM UserAddedRecord WHERE user_id='$id'";
    $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
    $Num_Rows = mysql_num_rows($objQuery);

    $Per_Page = 2;   // Per Page

    $Page = $_GET["Page"];
    if(!$_GET["Page"])
    {
        $Page=1;
    }

    $Prev_Page = $Page-1;
    $Next_Page = $Page+1;

    $Page_Start = (($Per_Page*$Page)-$Per_Page);
    if($Num_Rows<=$Per_Page)
    {
        $Num_Pages =1;
    }
    else if(($Num_Rows % $Per_Page)==0)
    {
        $Num_Pages =($Num_Rows/$Per_Page) ;
    }
    else
    {
        $Num_Pages =($Num_Rows/$Per_Page)+1;
        $Num_Pages = (int)$Num_Pages;
    }


    $strSQL .=" order  by id DESC LIMIT $Page_Start , $Per_Page";
    $objQuery  = mysql_query($strSQL);



    ?>
    <table width="600" border="1">
      <tr>
        <th width="50"> <div align="center">#</div></th>
        <th width="91"> <div align="center">ID </div></th>
        <th width="198"> <div align="center">First Name </div></th>
        <th width="198"> <div align="center">Last Name </div></th>
        <th width="250"> <div align="center">Mobile Company </div></th>
        <th width="100"> <div align="center">Cell </div></th>
        <th width="100"> <div align="center">Workphone </div></th>
        <th width="100"> <div align="center">Group </div></th>
      </tr>
    <?

echo "<form name='form1' method='post' action=''>";

    while($objResult = mysql_fetch_array($objQuery))
    {


echo "<tr>";
   echo "<td align='center'><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$objResult[addedrec_ID]\"></td>";
   echo "<td>$objResult[addedrec_ID] </td>";
   echo "<td>$objResult[FirstName]</td>";
   echo "<td>$objResult[LastName] </td>";
   echo "<td>$objResult[MobileCompany] </td>";
   echo "<td>$objResult[Cell] </td>";
   echo "<td>$objResult[WorkPhone] </td>";
   echo "<td>$objResult[Custgroup] </td>";

echo "</tr>";

    }


echo "<td colspan='7' align='center'><input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\">";

if($_POST['delete']) // from button name="delete"
     {
$checkbox = $_POST['checkbox']; //from name="checkbox[]"
         $countCheck = count($_POST['checkbox']);

for($d=0;$d<$countCheck;$d++)
         {
             $del_id  = $checkbox[$d];

$sql = "DELETE from UserAddedRecord where addedrec_ID = $del_id";

$result2=mysql_query($sql);

         }
             if($result2)
         {    
                 header('Location: customer-adddata.php');
             }
             else
             {
echo "Error: ".mysql_error();
             }
     }

echo "</form>";

    ?>
    </table>
    <br>
    Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
    <?
    if($Prev_Page)
    {
           if($_GET["txtFirstName"] == "")
                      {
        echo " <a href='$_SERVER[sCRIPT_NAME]?Page=$Prev_Page&txtLastName=$_GET[txtLastName]'><< Back</a> ";    
                      }

            else
                      {
        echo " <a href='$_SERVER[sCRIPT_NAME]?Page=$Prev_Page&txtFirstName=$_GET[txtFirstName]'><< Back</a> ";
                      }

    }

    for($i=1; $i<=$Num_Pages; $i++){
        if($i != $Page)
        {

            echo "[ <a href='$_SERVER[sCRIPT_NAME]?Page=$i&txtFirstName=$_GET[txtFirstName]'>$i</a> ]";    

        }
        else
        {
            echo "<b> $i </b>";
        }
    }
    if($Page!=$Num_Pages)
    {
              if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "")
                           {
                echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtCell=$_GET[txtCell]'>Next>></a> ";    
                           }
              else if($_GET["txtFirstName"] == "" )
                           {
            echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtLastName=$_GET[txtLastName]'>Next>></a> ";    
                           }
              else
                           {
                echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtFirstName=$_GET[txtFirstName]'>Next>></a> ";    }
                       }
    
    mysql_close($objConnect);



}


?>
</body>
</html>

 

Can I know how to solve this problem?

Thanks in advanced.

Link to comment
https://forums.phpfreaks.com/topic/249421-undefined-index-error-in-lampp/
Share on other sites

It runs without errors on your hosting server because error reporting is either off, or at a low level. You need to check if your variables have values before attempting to access them.

if( isset($variable) ) {
     // then do something
}

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.