Jump to content

php error on testing


gwh

Recommended Posts

Hi everyone,

 

I have a javascript-based slideshow type application and I'm using php to pull information from a database to populate the different categories within the application. This application/slideshow will have a number of categories, eg. suits, shirts, knitwear, etc. - all of which have their own populated table within my database. Most of the categories are fairly simple in that the data from their related tables is inserted into that category as is. Each of the categories has a description, however, for the shirts category this description will get inserted based on one of two scenarios occurring. There will either be just one description of the item OR the description will be broken up into two sections, ie. one for Ladies and the other for Men. An example follows:

 

Description

Ladies: 3/4 Sleeve with Roll Up Feature (Dual Sleeve), Placket Front, Shaped Hem, Semi-Fitted, 65% Polyester, 35% Cotton.

 

Men: Long Sleeve, Regular Collar, Business Cuff, Tailored Fit, 65% Polyester, 35% Cotton. Also available in Short Sleeve (Blue and White only).

 

If an item has a description for both ladies AND men, then both these will get inserted, however if there's only the one description (be it ladies OR men), then only that one description gets inserted. The headings "Ladies" and "Men" only appear if there's the two descriptions together. If there's just the one then the only heading will be "Description" and this will be in the XHTML.

 

To accommodate this, I made sure there were two separate columns in my 'shirts' database table one called "shirtDescLadies" and the other called "shirtDescMen", then the aim of the script would be to look at both of these cells and then check if they're empty and if it's an empty cell then that isn't available.

 

There will be other data pulled from the same 'shirts' database table, such as shirtTitle, shirtPrice, shirtColours etc so I wasn't sure if I needed two record sets, ie. one for the description and the other for the remainder of the table columns. Not knowing at this point, I decided to create the two separate record sets. The following shows the code that I'm using to handle the description part of the application for the shirts section (and the full code is at the end of this post):

 

$shirtID = 4; //The shirtID of the item you are currently viewing

//record set for the 2 description columns + the primary key column
mysql_select_db($database_localhost, $localhost);
$query_rsShirt_Desc = "SELECT shirtID, shirtDescLadies, shirtDescMen FROM shirts WHERE shirtID = '$shirtID'";
$rsShirt_Desc = mysql_query($query_rsShirt_Desc, $localhost) or die(mysql_error());
$row_rsShirt_Desc = mysql_fetch_assoc($rsShirt_Desc);
$totalRows_rsShirt_Desc = mysql_num_rows($rsShirt_Desc);


//1=ladies, 2=mens, 3=both
$descAvailable = 0;
$ladiesDesc = $row_rsShirt_Desc['shirtDescLadies'];
$mensDesc = $row_rsShirt_Desc['shirtDescMen']; 

//Add 1 if ladies available
//Will be set to 1 if only ladies available
if ($ladiesDesc != "")
{ $descAvailable = $descAvailable+1; } 

//Add 2 if mens available
//If ladies is available too this will now be set at 3 (both available)
//Otherwise it will remain at 2 (mens available)
if ($mensDesc != "")
{ $descAvailable = $descAvailable+2; } 
//Show ladies description if descAvailable is set to ladies or both
if (($descAvailable == 1) || ($descAvailable == 3))
{
        if ($descAvailable == 3) // Only echo heading if available description is both
        { echo "Ladies: <BR>"; } 
        echo $ladiesDesc; //always echo this is both or ladies
} 
//Show mens description if descAvailable is set to mens or both
if (($descAvailable == 2) || ($descAvailable == 3))
{
        if ($descAvailable == 3)// Only echo heading if available description is both
        { echo "Mens: <BR>"; } 
        echo $mensDesc; //always echo this is both or mens
}
?>

 

When I test at this point, the application loads but I get the following error notice in the application itself:

 

Notice: Undefined index: shirtDescLadies in /Applications/MAMP/htdocs/new_site/catalogue.php on line 154

 

LIne 154 is this line further down in the code which is where I'm trying to insert it:

 

       

<p>Description: <?php echo $row_rsShirts['shirtDescLadies']; ?></p>

 

Could this be because the code is positioned incorrectly? I mean should the php code listed at the top of this post be somewhere around the above code for Description since this is the point in the code where the description data needs to go?

 

I'm still quite new to php so would really be grateful if someone could help me troubleshoot.

 

<?php require_once('../Connections/localhost.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_localhost, $localhost);
$query_rstSuits = "SELECT suitTitle, suitSKU, suitDesc, suitPrice, suitColours, suitSizes, suitImage FROM suits";
$rstSuits = mysql_query($query_rstSuits, $localhost) or die(mysql_error());
$row_rstSuits = mysql_fetch_assoc($rstSuits);
$totalRows_rstSuits = mysql_num_rows($rstSuits);

mysql_select_db($database_localhost, $localhost);
$query_rsShirts = "SELECT shirtID, shirtTitle, shirtSKU, shirtPrice, shirtColours, shirtSizes, shirtImage, shirtSwatch FROM shirts";
$rsShirts = mysql_query($query_rsShirts, $localhost) or die(mysql_error());
$row_rsShirts = mysql_fetch_assoc($rsShirts);
$totalRows_rsShirts = mysql_num_rows($rsShirts);

$shirtID = 4; //The shirtID of the item you are currently viewing

mysql_select_db($database_localhost, $localhost);
$query_rsShirt_Desc = "SELECT shirtID, shirtDescLadies, shirtDescMen FROM shirts WHERE shirtID = '$shirtID'";
$rsShirt_Desc = mysql_query($query_rsShirt_Desc, $localhost) or die(mysql_error());
$row_rsShirt_Desc = mysql_fetch_assoc($rsShirt_Desc);
$totalRows_rsShirt_Desc = mysql_num_rows($rsShirt_Desc);




//1=ladies, 2=mens, 3=both
$descAvailable = 0;
$ladiesDesc = $row_rsShirt_Desc['shirtDescLadies'];
$mensDesc = $row_rsShirt_Desc['shirtDescMen']; 

//Add 1 if ladies available
//Will be set to 1 if only ladies available
if ($ladiesDesc != "")
{ $descAvailable = $descAvailable+1; } 

//Add 2 if mens available
//If ladies is available too this will now be set at 3 (both available)
//Otherwise it will remain at 2 (mens available)
if ($mensDesc != "")
{ $descAvailable = $descAvailable+2; } 
//Show ladies description if descAvailable is set to ladies or both
if (($descAvailable == 1) || ($descAvailable == 3))
{
        if ($descAvailable == 3) // Only echo heading if available description is both
        { echo "Ladies: <BR>"; } 
        echo $ladiesDesc; //always echo this is both or ladies
} 
//Show mens description if descAvailable is set to mens or both
if (($descAvailable == 2) || ($descAvailable == 3))
{
        if ($descAvailable == 3)// Only echo heading if available description is both
        { echo "Mens: <BR>"; } 
        echo $mensDesc; //always echo this is both or mens
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--[if IE]><script language="javascript" type="text/javascript" src="../dmx/lib/excanvas-compressed.js"></script><![endif]-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="../dmx/widgets/Lightbox/styles/default/style.css" />
<script language="javascript" type="text/javascript" src="../ScriptLibrary/jquery-latest.pack.js"></script>
<script language="javascript" type="text/javascript" src="../dmx/dmx.core.js" id="dmxCoreJS"></script>
<script language="javascript" type="text/javascript" src="../dmx/widgets/Lightbox/dmx.lightbox.js"></script>
<script type="text/javascript">
<!--
function openDMXzoneLightbox(arg, options, context) {//v1.2
	context = context || window, options = options || {};
	if (context.DMX && context.DMX.Lightbox) {
		context.DMX.Lightbox.open(options.plugin || "", arg, options);
      document.MM_returnValue = false;
	}
}
//-->
</script>
<script src="../ScriptLibrary/jquery.easing.1.3.js" type="text/javascript"></script>
<script src="../ScriptLibrary/jquery.mousewheel.pack.js" type="text/javascript"></script>
<script src="../ScriptLibrary/dmxSlidingBillboard.js" type="text/javascript"></script>
<link href="../Styles/dmxSlidingBillboard.css" rel="stylesheet" type="text/css" />
<link href="../Styles/dmxSlidingBillboard/dark_blue/dark_blue.css" rel="stylesheet" type="text/css" />
</head>

<body>
    <div class="dmxBillboard dark_blue" id="Corporatewear" style="width:656px;height:396px;">
  <div class="dmxBillboardHeader">
    <h3>Corporate Wear</h3>
    <div class="dmxBillboardSectionNav">
      <a href="#sec_1">Suits</a>
      <a href="#sec_2">Shirts/Blouses</a>
      <a href="#sec_3">Jackets</a>
      <a href="#sec_4">Skirts</a>
      <a href="#sec_5">Knitwear</a>
      <a href="#sec_6">Accessories</a>
      <div style="clear:both"></div>
    </div>
    <div style="clear:both;"></div>
  </div>
  <div class="dmxBillboardView layout-left">
    <ul id="sec_1" title="Suits"><?php do { ?>
      <li onclick="openDMXzoneLightbox('../images/corp/corporate/suits/<?php echo $row_rstSuits['suitImage']; ?>', {title:'Casual Suit', width:650, height:776}, window);return document.MM_returnValue">
        <a href="javascript:void(0);" onclick="openDMXzoneLightbox('../images/corp/corporate/suits/<?php echo $row_rstSuits['suitImage']; ?>', {title:'Casual Suit', width:650, height:776}, window);return document.MM_returnValue">
        <img src="../images/corp/corporate/suits/<?php echo $row_rstSuits['suitImage']; ?>" border="0" alt="" />
        </a>
      </li>
      <li title="<?php echo $row_rstSuits['suitTitle']; ?>">
                <h4><?php echo $row_rstSuits['suitTitle']; ?></h4>
        <p>Style Number: <?php echo $row_rstSuits['suitSKU']; ?></p>
        <p>Description: <?php echo $row_rstSuits['suitDesc']; ?></p>
        <p>Price: $<?php echo $row_rstSuits['suitPrice']; ?> </p>
        <p>Sizes: <?php echo $row_rstSuits['suitSizes']; ?> </p>
      </li><?php } while ($row_rstSuits = mysql_fetch_assoc($rstSuits)); ?>
    </ul>
    <ul id="sec_2" title="Shirts/Blouses"> <?php do { ?>
      <li onclick="openDMXzoneLightbox('../images/corp/corporate/shirts_blouses/<?php echo $row_rsShirts['shirtImage']; ?>', {width:650, height:776}, window);return document.MM_returnValue">
        <a href="javascript:void(0);" onclick="openDMXzoneLightbox('../images/corp/corporate/shirts_blouses/<?php echo $row_rsShirts['shirtImage']; ?>', {width:650, height:776}, window);return document.MM_returnValue">
        <img src="../images/corp/corporate/shirts_blouses/<?php echo $row_rsShirts['shirtImage']; ?>" border="0" alt="" />
        </a>
      </li>
      <li title="<?php echo $row_rsShirts['shirtTitle']; ?>">
                <h4><?php echo $row_rsShirts['shirtTitle']; ?></h4>
                <p>Style Number: <?php echo $row_rsShirts['shirtSKU']; ?></p>
                <p>Description: <?php echo $row_rsShirts['shirtDescLadies']; ?></p>
                <p>Price: <?php echo $row_rsShirts['shirtPrice']; ?></p>
                <p>Sizes: <?php echo $row_rsShirts['shirtSizes']; ?></p>
      </li><?php } while ($row_rsShirts = mysql_fetch_assoc($rsShirts)); ?>
    </ul>
    <ul id="sec_3" title="Jackets">
      <li onclick="openDMXzoneLightbox('../images/corp/corporate/shirts_blouses/cc2100_4100Large.jpg', {width:650, height:776}, window);return document.MM_returnValue">
        <a href="javascript:void(0);" onclick="openDMXzoneLightbox('../images/corp/corporate/shirts_blouses/cc2100_4100Large.jpg', {width:650, height:776}, window);return document.MM_returnValue">
        <img src="../images/corp/corporate/jackets/kcJacket.jpg" border="0" alt="" />
        </a>
      </li>
      <li title="some text">
                <h4>some text</h4>
      </li>
    </ul>
    <ul id="sec_4" title="Skirts">
      <li onclick="openDMXzoneLightbox('../images/corp/corporate/skirts/kcSkirt.jpg', {width:650, height:776}, window);return document.MM_returnValue">
        <a href="javascript:void(0);" onclick="openDMXzoneLightbox('../images/corp/corporate/skirts/kcSkirt.jpg', {width:650, height:776}, window);return document.MM_returnValue">
        <img src="../images/corp/corporate/skirts/kcSkirt.jpg" border="0" alt="" />
        </a>
      </li>
      <li title="some text">
                <h4>some text</h4>
      </li>
    </ul>
    <ul id="sec_5" title="Knitwear">
      <li onclick="openDMXzoneLightbox('../images/corp/corporate/knitwear/MF8003_8002Large.jpg', {width:650, height:776}, window);return document.MM_returnValue">
        <a href="javascript:void(0);" onclick="openDMXzoneLightbox('../images/corp/corporate/knitwear/MF8003_8002Large.jpg', {width:650, height:776}, window);return document.MM_returnValue">
        <img src="../images/corp/corporate/knitwear/MF8003_8002Large.jpg" border="0" alt="" />
        </a>
      </li>
      <li title="some text">
                <h4>some text</h4>
      </li>
    </ul>
    <ul id="sec_6" title="Accessories">
      <li onclick="openDMXzoneLightbox('../images/corp/corporate/accessories/kcScarves.jpg', {width:650, height:776}, window);return document.MM_returnValue">
        <a href="javascript:void(0);" onclick="openDMXzoneLightbox('../images/corp/corporate/accessories/kcScarves.jpg', {width:650, height:776}, window);return document.MM_returnValue">
        <img src="../images/corp/corporate/accessories/kcScarves.jpg" border="0" alt="" />
        </a>
      </li>
      <li title="some text">
                <h4>some text</h4>
      </li>
    </ul>
  </div>
  <div class="dmxBillboardFooter">
    <div class="dmxBillboardPageNav"></div>
    <div style="clear:both;"></div>
  </div>
<div class="dmxBillboardLeftNav middle"></div>
<div class="dmxBillboardRightNav middle"></div>
</div>
<script type="text/javascript">
  // <![CDATA[
jQuery(document).ready(
   function()
     {
       jQuery("#Corporatewear").dmxSlidingBillboard(
         {
            width: '656',
            height: 396,
            columns: 2,
            rows: 1,
            scrollInterval: 5000,
            scrollDuration: 'normal',
            navPos: 'top',
            secPagingPos: 'bottom',
            design: 'dark_blue',
            layoutStyle: 'left',
            scrollEasing: 'swing',
            sideNavPos: 'middle',
            horizontal: true,
            keyboard: true,
            mousewheel: true,
            autoPlay: true,
            imageMaxWidth: '100%',
            imageMaxHeight: '100%',
            showSideNavOnMouseOver: false,
            imageScaleUp: false,
            startSection: 1,
            startIndex: 1,
            autoNextSection: true
        }
       );
     }
);
  // ]]>
</script>
</body>
</html>
<?php
mysql_free_result($rstSuits);

mysql_free_result($rsShirts);

mysql_free_result($rsShirt_Desc);
?>

 

 

Link to comment
Share on other sites

I think your problem is that your trying to get information from $row_rsShirts which doesn't exist because you selected them separately here:

 

$ladiesDesc = $row_rsShirt_Desc['shirtDescLadies'];
$mensDesc = $row_rsShirt_Desc['shirtDescMen']; 

 

If you tried:

 

<p>Description: <?php echo $row_rsShirts_Desc['shirtDescLadies']; ?></p>

 

I'm sure that would work.

Link to comment
Share on other sites

I've just tried moving the code from the top of the document to the place where I was getting the error so that part of the code now looks like this:

 

      <li title="<?php echo $row_rsShirts['shirtTitle']; ?>">
                <h4><?php echo $row_rsShirts['shirtTitle']; ?></h4>
                <p>Style Number: <?php echo $row_rsShirts['shirtSKU']; ?></p>
                <p>Description: <?php //Add 1 if ladies available
//Will be set to 1 if only ladies available
if ($ladiesDesc != "")
{ $descAvailable = $descAvailable+1; } 

//Add 2 if mens available
//If ladies is available too this will now be set at 3 (both available)
//Otherwise it will remain at 2 (mens available)
if ($mensDesc != "")
{ $descAvailable = $descAvailable+2; } 
//Show ladies description if descAvailable is set to ladies or both
if (($descAvailable == 1) || ($descAvailable == 3))
{
        if ($descAvailable == 3) // Only echo heading if available description is both
        { echo "Ladies: <BR>"; } 
        echo $ladiesDesc; //always echo this is both or ladies
} 
//Show mens description if descAvailable is set to mens or both
if (($descAvailable == 2) || ($descAvailable == 3))
{
        if ($descAvailable == 3)// Only echo heading if available description is both
        { echo "Mens: <BR>"; } 
        echo $mensDesc; //always echo this is both or mens
}
?></p>

 

When I test now, I don't get any error but there is no description showing at all even though I know there is some data in the database.

 

Does anyone know what's going on?

Link to comment
Share on other sites

I must have posted my last comment at the same time as you did. I went back and tried your suggestion but I get the following error:

 

Notice: Undefined variable: row_rsShirts_Desc in /Applications/MAMP/htdocs/new_site/catalogue.php on line 154

 

Link to comment
Share on other sites

It seems like it's not being populated correctly at this stage;

 

$query_rsShirt_Desc = "SELECT shirtID, shirtDescLadies, shirtDescMen FROM shirts WHERE shirtID = '$shirtID'";
$rsShirt_Desc = mysql_query($query_rsShirt_Desc, $localhost) or die(mysql_error());
$row_rsShirt_Desc = mysql_fetch_assoc($rsShirt_Desc);

 

After this code, write this:

 

die(print_r($row_rsShirt_Desc));

 

And see if it is returning any information at all.

Link to comment
Share on other sites

That means there is a problem with your SQL query:

 

$query_rsShirt_Desc = "SELECT shirtID, shirtDescLadies, shirtDescMen FROM shirts WHERE shirtID = '$shirtID'";

 

Double check the field names are working fine and make sure $shirtID has a correct value.

Link to comment
Share on other sites

Ok so I noticed that the following variable is set to 4 but the primary key of the first database record is set to 9. So I changed it from:

 

$shirtID = 4; //The shirtID of the item you are currently viewing

 

to

 

$shirtID = 9;

 

When I test, the following which is the data for the first record shows up above the application and not within the application where it's supposed to be:

 

Ladies:

Example A: 3/4 Sleeve with Roll Up Feature, 65% Polyester, 35% Cotton.Mens:

3/4 Sleeve with Roll Up Feature, 65% Polyester, 35% Cotton.

 

But in addition to this, the following shows up at the correct place within the application:

 

Description: Example A: 3/4 Sleeve with Roll Up Feature, 65% Polyester, 35% Cotton.

 

The above data (which should only go on the first slide) is showing for all 5 shirt slides.

 

I moved the positioning of the code further down as mentioned in an earlier post to the following:

 

      <li title="<?php echo $row_rsShirts['shirtTitle']; ?>">
                <h4><?php echo $row_rsShirts['shirtTitle']; ?></h4>
                <p>Style Number: <?php echo $row_rsShirts['shirtSKU']; ?></p>
                <p>Description: <?php //Add 1 if ladies available
//Will be set to 1 if only ladies available
if ($ladiesDesc != "")
{ $descAvailable = $descAvailable+1; } 

//Add 2 if mens available
//If ladies is available too this will now be set at 3 (both available)
//Otherwise it will remain at 2 (mens available)
if ($mensDesc != "")
{ $descAvailable = $descAvailable+2; } 
//Show ladies description if descAvailable is set to ladies or both
if (($descAvailable == 1) || ($descAvailable == 3))
{
        if ($descAvailable == 3) // Only echo heading if available description is both
        { echo "Ladies: <BR>"; } 
        echo $ladiesDesc; //always echo this is both or ladies
} 
//Show mens description if descAvailable is set to mens or both
if (($descAvailable == 2) || ($descAvailable == 3))
{
        if ($descAvailable == 3)// Only echo heading if available description is both
        { echo "Mens: <BR>"; } 
        echo $mensDesc; //always echo this is both or mens
}
?></p>

 

This inserts the correct data on the first shirts slide within the application where it should go, however all following shirts, ie. from 2 - 5, all have no data.

 

I can't work it out.

Link to comment
Share on other sites

I'm not sure how to explain further. After moving the code from the top part of the file to the point in the file where the description needs to be inserted, it's only inserting the first record and not any of the others.

 

Anyone-else have any input? Would really appreciate it.

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.