Jump to content

[SOLVED] Help needed with passing 'id' through url


imimin

Recommended Posts

I did it like this:

 

					if($get_items){
				   $item_row = mysql_fetch_assoc($get_items);
				   extract($item_row);
				   $price = $retail * .75;
				   echo <<<HTML


				<IMG SRC=\includes/img_resize3.php?src=$sitelocation$img&width=175&height=175&qua=100\" BORDER=\"0\">

				<BR>
    			Sample image of selected
    			<BR>garment</P>

 

and it did not work.  I am pretty sure I need to have the "echo <<<HTML" where I have it, it won't work if I put it in 2 or more places, right??

Link to comment
Share on other sites

  • Replies 92
  • Created
  • Last Reply

Does not work.  Setting up like this:

 

$price = $retail * .75;
<<<HTML
<input type='hidden' name='name' value='$prod_name' />
<input type='hidden' name='price' value='$retail' />

 

Getting following error:

 

Notice: Undefined variable: price in /homepages/27/d120150310/htdocs/poj/poj_order_form.php on line 247

 

and the following is printing when it should not:

 

= 42.99 * .75; << 

Link to comment
Share on other sites

Getting following errors:

 

Notice: Undefined variable: price in /homepages/27/d120150310/htdocs/poj/poj_order_form.php on line 247

Notice: Undefined variable: price in /homepages/27/d120150310/htdocs/poj/poj_order_form.php on line 251

 

and printing incorrectly:

 

= 39.99 * .75; << 

Link to comment
Share on other sites

It is outside the heredoc!

 

					<?php
				/* Enable displaying of errors */
				error_reporting(E_ALL);
				ini_set('display_errors', 'On');

				// Ensure id was set
				if(!isset($_GET['id'])){
				   die("Id isn't set");
				}

				// Clean the id
				$id = mysql_real_escape_string($_GET['id']);

				// Query Database
				$get_items = "SELECT * FROM poj_products WHERE `id` = '$id'";
				$get_items = mysql_query($get_items);
				if($get_items){
				   $item_row = mysql_fetch_assoc($get_items);
				   extract($item_row);
				   echo <<<HTML


				<IMG SRC=\includes/img_resize3.php?src=$sitelocation$img&width=175&height=175&qua=100\" BORDER=\"0\">

				HTML;

				<BR>
    			Sample image of selected
    			<BR>garment</P>
    			</TD>
				<TD width=25%>

				<B>Garment Color:</B>
	 <SCRIPT LANGUAGE="javascript">

         GarmentColorArray = new Array (9);

            GarmentColorArray[1] = "RedHib2.jpg";

            GarmentColorArray[2] = "DarkBlueHib2.jpg";

            GarmentColorArray[3] = "TurquoiseHib3.jpg";

            GarmentColorArray[4] = "PurpleHib2.jpg";

            GarmentColorArray[5] = "blue.jpg";

            GarmentColorArray[6] = "white.jpg";

            GarmentColorArray[7] = "pink.jpg";

            GarmentColorArray[8] = "AmerFlag.jpg";

            GarmentColorArray[9] = "100DollarBill.jpg";

            function GarmentColorImageSwap(imgBase,imgIndex)
             {
            Index = imgIndex + 1;
            document.GarmentColorImage.src = '/images/swatches/' +
               GarmentColorArray[index];
             }

			</SCRIPT>

<script language="JavaScript">

/***********************************************
* Required field(s) validation v1.10- By NavSurf
* Visit Nav Surf at http://navsurf.com
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("custom10", "custom20", "custom30", "custom40");
// Enter field description to appear in the dialog box
var fieldDescription = Array("Garment Color", "Garment Style", "Size Range", "Garment Size");
// dialog message
var alertMsg = "Please complete the following fields:\n";

var l_Msg = alertMsg.length;

for (var i = 0; i < fieldRequired.length; i++){
	var obj = formobj.elements[fieldRequired[i]];
	if (obj){
		switch(obj.type){
		case "select-one":
			if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
				alertMsg += " - " + fieldDescription[i] + "\n";
			}
			break;
		case "select-multiple":
			if (obj.selectedIndex == -1){
				alertMsg += " - " + fieldDescription[i] + "\n";
			}
			break;
		case "text":
		case "textarea":
			if (obj.value == "" || obj.value == null){
				alertMsg += " - " + fieldDescription[i] + "\n";
			}
			break;
		default:
		}
		if (obj.type == undefined){
			var blnchecked = false;
			for (var j = 0; j < obj.length; j++){
				if (obj[j].checked){
					blnchecked = true;
				}
			}
			if (!blnchecked){
				alertMsg += " - " + fieldDescription[i] + "\n";
			}
		}
	}
}

if (alertMsg.length == l_Msg){
	return true;
}else{
	alert(alertMsg);
	return false;
}
}
</script>

<FORM METHOD=POST ACTION="https://secure.impact-impressions.com/cgi-bin/cart.pl" onsubmit="return formCheck(this);">

<SELECT NAME="custom10" SIZE=9 ONCHANGE="GarmentColorImageSwap('GarmentColorImage', this.selectedIndex)" SIZE="1">
<OPTION VALUE='Color: RED Hibiscus'>RED Hibiscus</OPTION>
<OPTION VALUE='Color: Dark Blue Hibiscus'>Dark Blue Hibiscus</OPTION>
<OPTION VALUE='Color: Turquoise Hibiscus'>Turquoise Hibiscus</OPTION>
<OPTION VALUE='Color: Purple Hibiscus'>Purple Hibiscus</OPTION>
<OPTION VALUE='Color: Blue'>Blue</OPTION>
<OPTION VALUE='Color: White'>White</OPTION>
<OPTION VALUE='Color: Pink'>Pink</OPTION>
<OPTION VALUE='Color: American Flag'>American Flag</OPTION>
<OPTION VALUE='Color: Hundred Dollar Bill'>Hundred Dollar Bill</OPTION>
</SELECT> <BR>
<A HREF="javascript:newwindow()" >View All Color Choices</A> 

			</TD>
			 <TD ROWSPAN=2 valign="top"><P align=center><IMG ALIGN='top' BORDER='0' HEIGHT='175' NAME='GarmentColorImage'
			 SRC='/images/swatches/blank.jpg' WIDTH='175'>
			 <BR>
			 Image of Garment Color
			 <BR>selected. NOTE: Colors
			 <BR>may vary.</P>
			 </TD>
				</TR>

				<TR>
				<TD>

$price = $retail * .75;
<<<HTML
<input type='hidden' name='name' value='$prod_name' />
<input type='hidden' name='price' value='$price' />
<input type='hidden' name='sh' value='$weight' />
<input type='hidden' name='img' value='https://secure.impact-impressions.com/poj/includes/img_resize3.php?src=$sitelocation$img&width=100&height=100&qua=50' />
<input type='hidden' name='img2' value='' />
<input type='hidden' name='return' value='http://www.patternsofjoy.com/order_more.php' />
   <input type='RADIO' name='custom20' value='Style: $selected_style' checked='checked' style='display: none' />
<strong>Garment Style: </strong>$selected_style
<br />


				<a href="http://www.patternsofjoy.com/order_more.php" TITLE="Click here to change Garement Style">***Change Garment Style***</a>

			 </TD>
			 </TR>
			<TR>
			<TD>
			<B>Size Range:</B><BR>
			<INPUT TYPE="RADIO" NAME=custom30 VALUE="Size Range: Adult +$2.00"> Adult
			<INPUT TYPE="RADIO" NAME=custom30 VALUE="Size Range: Child"> Child<BR>
			</TD>



               <td>
               Adult and Teen Sizing Chart:
                  $adult_size_chart<br />
               </td>
            </tr>
            <tr>
               <td>
                  <strong>Garmet Size:</strong>
                  <select id="custom40" name="custom40" size='5'>
                     <option value="Size: Small (S)">Small (S)</option>
                     <option value="Size: Medium (M)">Medium (M)</option>
                     <option value="Size: Large (L)">Large (L)</option>
                     <option value="Size: Extra Large (L)">Extra Large (L)</option>
                     <option value="Size: Toddler (T)">Toddler (T)</option>
                  </select><br />
                  <a href="javascript:newwindow2();" >Garment Measuring Tips</a>
               </td>
               <td>
                  Child Sizing Chart:
                  $child_size_chart<br />
               </td>
            </tr>
HTML;
            }else{
            die("Unable to connect to database.".mysql_error());
         }
         ?>

Link to comment
Share on other sites

No... you see how the heredoc started on line 20 is never ended, so you actually have a heredoc within a heredoc.

 

Try the following:

 

               <?php
               /* Enable displaying of errors */
               error_reporting(E_ALL);
               ini_set('display_errors', 'On');

               // Ensure id was set
               if(!isset($_GET['id'])){
                  die("Id isn't set");
               }

               // Clean the id
               $id = mysql_real_escape_string($_GET['id']);

               // Query Database
               $get_items = "SELECT * FROM poj_products WHERE `id` = '$id'";
               $get_items = mysql_query($get_items);
               if($get_items){
                  $item_row = mysql_fetch_assoc($get_items);
                  extract($item_row);
                  echo <<<HTML


               <IMG SRC="includes/img_resize3.php?src=$sitelocation$img&width=175&height=175&qua=100" BORDER="0">

               HTML;

               <BR>
                Sample image of selected
                <BR>garment</P>
                </TD>
               <TD width=25%>

               <B>Garment Color:</B>
       <SCRIPT LANGUAGE="javascript">

         GarmentColorArray = new Array (9);

            GarmentColorArray[1] = "RedHib2.jpg";

            GarmentColorArray[2] = "DarkBlueHib2.jpg";

            GarmentColorArray[3] = "TurquoiseHib3.jpg";

            GarmentColorArray[4] = "PurpleHib2.jpg";

            GarmentColorArray[5] = "blue.jpg";

            GarmentColorArray[6] = "white.jpg";

            GarmentColorArray[7] = "pink.jpg";

            GarmentColorArray[8] = "AmerFlag.jpg";

            GarmentColorArray[9] = "100DollarBill.jpg";

            function GarmentColorImageSwap(imgBase,imgIndex)
             {
            Index = imgIndex + 1;
            document.GarmentColorImage.src = '/images/swatches/' +
               GarmentColorArray[index];
             }

          </SCRIPT>

<script language="JavaScript">

/***********************************************
* Required field(s) validation v1.10- By NavSurf
* Visit Nav Surf at http://navsurf.com
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function formCheck(formobj){
   // Enter name of mandatory fields
   var fieldRequired = Array("custom10", "custom20", "custom30", "custom40");
   // Enter field description to appear in the dialog box
   var fieldDescription = Array("Garment Color", "Garment Style", "Size Range", "Garment Size");
   // dialog message
   var alertMsg = "Please complete the following fields:\n";

   var l_Msg = alertMsg.length;

   for (var i = 0; i < fieldRequired.length; i++){
      var obj = formobj.elements[fieldRequired[i]];
      if (obj){
         switch(obj.type){
         case "select-one":
            if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
               alertMsg += " - " + fieldDescription[i] + "\n";
            }
            break;
         case "select-multiple":
            if (obj.selectedIndex == -1){
               alertMsg += " - " + fieldDescription[i] + "\n";
            }
            break;
         case "text":
         case "textarea":
            if (obj.value == "" || obj.value == null){
               alertMsg += " - " + fieldDescription[i] + "\n";
            }
            break;
         default:
         }
         if (obj.type == undefined){
            var blnchecked = false;
            for (var j = 0; j < obj.length; j++){
               if (obj[j].checked){
                  blnchecked = true;
               }
            }
            if (!blnchecked){
               alertMsg += " - " + fieldDescription[i] + "\n";
            }
         }
      }
   }

   if (alertMsg.length == l_Msg){
      return true;
   }else{
      alert(alertMsg);
      return false;
   }
}
</script>

<FORM METHOD=POST ACTION="https://secure.impact-impressions.com/cgi-bin/cart.pl" onsubmit="return formCheck(this);">

   <SELECT NAME="custom10" SIZE=9 ONCHANGE="GarmentColorImageSwap('GarmentColorImage', this.selectedIndex)" SIZE="1">
   <OPTION VALUE='Color: RED Hibiscus'>RED Hibiscus</OPTION>
   <OPTION VALUE='Color: Dark Blue Hibiscus'>Dark Blue Hibiscus</OPTION>
   <OPTION VALUE='Color: Turquoise Hibiscus'>Turquoise Hibiscus</OPTION>
   <OPTION VALUE='Color: Purple Hibiscus'>Purple Hibiscus</OPTION>
   <OPTION VALUE='Color: Blue'>Blue</OPTION>
   <OPTION VALUE='Color: White'>White</OPTION>
   <OPTION VALUE='Color: Pink'>Pink</OPTION>
   <OPTION VALUE='Color: American Flag'>American Flag</OPTION>
   <OPTION VALUE='Color: Hundred Dollar Bill'>Hundred Dollar Bill</OPTION>
</SELECT> <BR>
<A HREF="javascript:newwindow()" >View All Color Choices</A> 

            </TD>
             <TD ROWSPAN=2 valign="top"><P align=center><IMG ALIGN='top' BORDER='0' HEIGHT='175' NAME='GarmentColorImage'
             SRC='/images/swatches/blank.jpg' WIDTH='175'>
             <BR>
             Image of Garment Color
             <BR>selected. NOTE: Colors
             <BR>may vary.</P>
             </TD>
               </TR>

               <TR>
               <TD>
HTML;
   $price = $retail * .75;

   echo <<<HTML
   <input type='hidden' name='name' value='$prod_name' />
   <input type='hidden' name='price' value='$price' />
   <input type='hidden' name='sh' value='$weight' />
   <input type='hidden' name='img' value='https://secure.impact-impressions.com/poj/includes/img_resize3.php?src=$sitelocation$img&width=100&height=100&qua=50' />
   <input type='hidden' name='img2' value='' />
   <input type='hidden' name='return' value='http://www.patternsofjoy.com/order_more.php' />
   <input type='RADIO' name='custom20' value='Style: $selected_style' checked='checked' style='display: none' />
   <strong>Garment Style: </strong>$selected_style
   <br />


               <a href="http://www.patternsofjoy.com/order_more.php" TITLE="Click here to change Garement Style">***Change Garment Style***</a>

             </TD>
             </TR>
            <TR>
            <TD>
            <B>Size Range:</B><BR>
            <INPUT TYPE="RADIO" NAME=custom30 VALUE="Size Range: Adult +$2.00"> Adult
            <INPUT TYPE="RADIO" NAME=custom30 VALUE="Size Range: Child"> Child<BR>
            </TD>



               <td>
               Adult and Teen Sizing Chart:
                  $adult_size_chart<br />
               </td>
            </tr>
            <tr>
               <td>
                  <strong>Garmet Size:</strong>
                  <select id="custom40" name="custom40" size='5'>
                     <option value="Size: Small (S)">Small (S)</option>
                     <option value="Size: Medium (M)">Medium (M)</option>
                     <option value="Size: Large (L)">Large (L)</option>
                     <option value="Size: Extra Large (L)">Extra Large (L)</option>
                     <option value="Size: Toddler (T)">Toddler (T)</option>
                  </select><br />
                  <a href="javascript:newwindow2();" >Garment Measuring Tips</a>
               </td>
               <td>
                  Child Sizing Chart:
                  $child_size_chart<br />
               </td>
            </tr>
HTML;
            }else{
            die("Unable to connect to database.".mysql_error());
         }
         ?>

Link to comment
Share on other sites

Yeah... the logic to calculate the price cannot be contained within heredoc.  So I ended the first heredoc on line 155 with the HTML;.  Then the $price is calculated, and a new heredoc is started, ending at line 205.

 

I'd recommend reading over the examples of heredoc at the url below.

http://us.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

Link to comment
Share on other sites

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.