Jump to content

How do i find out where is the error/problem in my code?


laanes

Recommended Posts

When clicking on the link "groups", there is no problem printing out the first level subgroups. But when clicking on any of the subgroup, the second level subgroups are not being displayed.

 

I have or die(mysql_error()); after some queries but I can not see what is the error.

 

It always gives the same message:

 

No Products Found.

Sorry, but there are no products in this section at the moment. The products are constantly being updated, however. Please try again later or contact us.

 

How would I find out which part of the code fails?

 

The code:

 

<?php
include 'scrptz/functions.php';

// Page vars
$thisPage=$getVars["page"];
if($thisPage<1)$thisPage=1;
$firstGroup=($thisPage*16)-16;

// Get group details and stick them into an array
$qMain="SELECT * FROM PGroups WHERE PG = '".$getVars["prodg"]."'";
$result=mysql_query($qMain)
or die(mysql_error());
$groupDetails=mysql_fetch_array($result);

// Get all sub groups in current product group
$qMain="SELECT * FROM SubG WHERE ProdG = '".$getVars["prodg"]."'";
$result=mysql_query($qMain)
or die(mysql_error());

// Stick sub groups in a 2D associative array
$j=0;
while ($row=mysql_fetch_array($result))
{
foreach($row as $i=>$data)$array[$j][$i]=$data;
$j++;
}

// Calculate vars for navigation
$totalGroups=$j;
$totalPages=ceil($totalGroups/16);

// Set page title (for bookmark)
$pageTitle=$groupDetails["GPname"];

// Set top title
if($totalGroups>0){$topTitle="VIEW PRODUCTS";}else{$topTitle="ERROR";}
?>
<html>
<head>
<title>Lock-Tech® Hi-Specification Architectural Hardware</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="scrptz/styles.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript">var theID="<?php echo $getVars['uid']; ?>";</script>
<script language="JavaScript" src="scrptz/content.js" type="text/javascript"></script>
<script language="JavaScript" src="scrptz/menu.js" type="text/javascript"></script>
<script language="JavaScript" src="scrptz/scripts.js" type="text/javascript"></script>
</head>
<body background="imgz/bg.gif" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0"<?php echo $notify ?>>
<?php include("top.php"); ?>
<table width="952" height="509" border="0" cellpadding="0" cellspacing="0" class="maintext">
<?php if($sessions['accCode']){?><form action="http://www.lock-tech.co.uk/index.php" method="post" name="logout" target="_parent"><input name="account" type="hidden" value="<?php echo $sessions['accCode']; ?>"><input name="killSession" type="hidden" value="<?php echo $getVars['uid']; ?>"></form><?php }?>
  <tr> 
    <td width="1" rowspan="5" bgcolor="#000000"></td>
    <td height="21" background="imgz/topbar.gif" bgcolor="#14359E"> </td>
    <td height="21" colspan="5" valign="middle" background="imgz/topbar.gif" bgcolor="#14359E" class="mainyellow"><?php include("scrptz/dd_menu.php"); ?></td>
    <td height="21" background="imgz/topbar.gif" bgcolor="#14359E"> </td>
    <td width="1" rowspan="5" bgcolor="#000000"></td>
  </tr>
  <tr> 
    <td width="5" rowspan="3"> </td>
    <td width="306" height="30" valign="bottom" class="title2"><?php echo $groupDetails["GPname"] ?></td>
    <td width="11" rowspan="3"><img src="imgz/maindiv.gif" width="11" height="466"></td>
    <td width="306" height="30" align="center" valign="bottom" class="title2"><?php if($totalGroups>0){?><a href="g_view.php?pgroup=<?php echo $groupDetails["PG"] ?>&uid=<?php echo $getVars['uid']; ?>" class="link4" onmouseover="window.status='View List of all Products in <?php echo $groupDetails["GPname"] ?>'; return true">VIEW ALL</a> | <a href="g_browse.php?pgroup=<?php echo $groupDetails["PG"] ?>&uid=<?php echo $getVars['uid']; ?>" class="link4" onmouseover="window.status='Browse all Products in <?php echo $groupDetails["GPname"] ?>'; return true">BROWSE ALL</a><?php }?></td>
    <td width="11" rowspan="3"><img src="imgz/maindiv.gif" width="11" height="466"></td>
    <td width="306" height="30" align="center" valign="bottom"> </td>
    <td width="5" rowspan="3"> </td>
  </tr>
  <tr> 
    <td height="20" valign="top" class="mainbold"></td>
    <td width="306" rowspan="2" valign="top" class="maintext">
      <?php for($i=$firstGroup; $i<($firstGroup+ && $i<$totalGroups; $i++){?>
      <a href="sub.php?PSubG=<?php echo $array[$i]["SPG"] ?>&uid=<?php echo $getVars['uid']; ?>" class="link1" onmouseover="window.status='View Products in <?php echo $array[$i]["SPGname"] ?>'; return true"><?php echo $array[$i]["SPGname"] ?></a><br>
		<?php
		// Get all subsubs in current sub group
		$qMain="SELECT * FROM SubSubG WHERE SPG = '".$array[$i]["SPG"]."'";
		$result=mysql_query($qMain)
		or die(mysql_error());

		// Print subsubs
		while ($row=mysql_fetch_array($result))
		{
		?>
			[<a href="subsub.php?PSubSubG=<?php echo $row["SSPG"]?>&uid=<?php echo $getVars['uid']; ?>" class="link3" onmouseover="window.status='View Products in <?php echo $row["SSPGName"]?>'; return true"><?php echo $row["SSPGName"]?></a>] 
		<?php
		}
		?>
		<br><br>
		<?php }?></td>
    <td width="306" rowspan="2" valign="top" class="maintext">
      <?php for($i=$firstGroup+8; $i<($firstGroup+16) && $i<$totalGroups; $i++){
  ?>
      <a href="sub.php?PSubG=<?php echo $array[$i]["SPG"] ?>&uid=<?php echo $getVars['uid']; ?>" class="link1" onmouseover="window.status='View Products in <?php echo $array[$i]["SPGname"] ?>'; return true"><?php echo $array[$i]["SPGname"] ?></a><br>
		<?php
		// Get all subsubs in current sub group
		$qMain="SELECT * FROM SubSubG WHERE SPG = '".$array[$i]["SPG"]."'";
		$result=mysql_query($qMain)
		or die("<font color=\"#FF0000\">ERROR {9.4}! Please navigate to a <a href=\"main.php?uid=".$getVars['uid']."\">different page</a> and then try this page again.</font>");

		// Print subsubs
		while ($row=mysql_fetch_array($result))
		{
		?>
			[<a href="subsub.php?PSubSubG=<?php echo $row["SSPG"]?>&uid=<?php echo $getVars['uid']; ?>" class="link3" onmouseover="window.status='View Products in <?php echo $row["SSPGName"]?>'; return true"><?php echo $row["SSPGName"]?></a>] 
		<?php
		}
		?>
		<br><br>
		<?php }?></td>
  </tr>
  <tr> 
    <td height="416" valign="top" class="mainbold">

<?php if($totalGroups>0)

{

?>

<img src="grp_pics/<?php echo $groupDetails["PG"] ?>.jpg" alt="Group Picture" galleryimg="no"><br><img src="imgz/pixel.gif" width="306" height="5"><br> 

<?php echo $groupDetails["GPText"] ?><?php  }

else
{
?>
	or die(mysql_error());	

	<p class="noresult">No Products Found.</p><p class="mainbold">Sorry, but there are no products in this section at the moment. The products are constantly being updated, however. Please try again later or <a href="mailto:sales@lock-tech.co.uk" class="link1" onmouseover="window.status='Send us an Email.'; return true">contact us</a>.</p><?php }?></td>
  </tr>
  <tr> 
    <td width="5" height="22" background="imgz/btmbar.gif" bgcolor="#14359E"> </td>
    <td width="306" height="22" align="center" valign="top" background="imgz/btmbar.gif" bgcolor="#14359E"><a href="javascript:history.back()" onmouseover="prev_btn.src='imgz/prev2.gif';window.status='Previous Page'; return true" onmouseout="prev_btn.src='imgz/prev.gif'"><img name="prev_btn" src="imgz/prev.gif" width="124" height="16" border="0"></a></td>
    <td width="11" height="22" bgcolor="#14359E"><img src="imgz/btmdiv.gif" width="11" height="22"></td>
    <td width="306" height="22" align="center" background="imgz/btmbar.gif" bgcolor="#14359E" class="nav"><? include 'scrptz/nav.php' ?></td>
    <td width="11" height="22" bgcolor="#14359E"><img src="imgz/btmdiv.gif" width="11" height="22"></td>
    <td width="306" height="22" align="center" valign="top" background="imgz/btmbar.gif" bgcolor="#14359E"><a href="javascript:directLink('<?php echo $prodLink; ?>','<? echo $pageTitle ?>')" onmouseover="link_btn.src='imgz/link2.gif'; window.status='Direct Link to This Page'; return true" onmouseout="link_btn.src='imgz/link.gif'"><img name="link_btn" src="imgz/link.gif" alt="" width="182" height="16" border="0"></a></td>
    <td width="5" height="22" background="imgz/btmbar.gif" bgcolor="#14359E"> </td>
  </tr>
</table>
</body>
</html>

Link to comment
Share on other sites

If you have or die() after all of your queries then there is no error with the db queries. If you are certain that there are records in teh db for what you "expect" to be displayed, then the problem is likely that the queries are getting created incorrectly (but in a valid format). So the result of the query is that a valid record set is returned - but the record set is empty. An empty record set is NOT an error.

 

You should add some debugging code to your page to echo the queries to the page along with a line that echos the count of the records returned from the query.

Link to comment
Share on other sites

I think it already is after every query in the code i posted, or not?

 

It still does not give me any errors.

 

oops ! Sorry ! Missed that..

As mjdamato suggested, try adding more debugging statements. You can echo out all queries and try manually firing them on the Database.

Link to comment
Share on other sites

Look what you did :

<?php echo $groupDetails["GPText"] ?><?php  }
else
{
?>

or die(mysql_error());	

<p class="noresult">No Products Found.</p><p class="mainbold">Sorry, but there are no products in this section at the moment. The products are constantly being updated, however. Please try again later or <a href="mailto:sales@lock-tech.co.uk" class="link1" onmouseover="window.status='Send us an Email.'; return true">contact us</a>.</p><?php }?></td>
  </tr>
  <tr> 

 

Of course this will show up every time there is no condition for it to be true or false besides the fact that your or die() is outside the php tag

Link to comment
Share on other sites

Thank you for your replies!

 

I have managed to display all the errors with this method:

 

ini_set('error_reporting', E_ALL);

 

I guess I now have what I was after. Errors that I don't know how to fix:

 

 

Notice: Undefined index: vat in /home/swansea3/public_html/lock-tech.co.uk/home/scrptz/sessions.php on line 39

 

Notice: Undefined index: action in /home/swansea3/public_html/lock-tech.co.uk/home/scrptz/sessions.php on line 62

 

Notice: Undefined index: UPDATE_x in /home/swansea3/public_html/lock-tech.co.uk/home/scrptz/sessions.php on line 62

 

Notice: Undefined index: DELETE_x in /home/swansea3/public_html/lock-tech.co.uk/home/scrptz/sessions.php on line 62

 

Notice: Undefined index: page in /home/swansea3/public_html/lock-tech.co.uk/home/groups.php on line 6

 

As these errors were not there before moving the website to the new host, could it be that it fails to connect to the database somewhere and these errors are being output because of that?

 

I know the errors tell exactly where the problem is but those files have not been changed for a long period of time and the website has been running without problems in the old server.

 

Link to comment
Share on other sites

In sessions.php there is a block of code:

 

$URLvars=substr($_SERVER["PHP_SELF"], strrpos($_SERVER["PHP_SELF"],"/")+1);
$vatLink=$URLvars;
$thisPageURL=$_SERVER["PHP_SELF"];
if(strpos($thisPageURL, "secure/locktech/")!==false)$thisPageURL=substr($_SERVER["PHP_SELF"], 16);
$prodLink="http://www.lock-tech.co.uk/".$thisPageURL;

 

Maybe the new server does not provide the necessary information that the old server did?

 

Reading from php.net:

 

$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here. That said, a large number of these variables are accounted for in the » CGI 1.1 specification, so you should be able to expect those.

 

Any opinions about this?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.