Jump to content

Recommended Posts

Hi, im a newbie to PHP and just trying to help out someone who is using the php integration kit. The problem is on the buildOrder.php page, if i add a value to the SQL to get products with a certain category id i can not then add them to the cart. When i choose a quantity and submit, nothing gets passed into the cart.

 

So if anyone could help me with this at all, that would be great, i presume its not much code to accept this but i don't have a clue what to do.

 

Thanks in anticipation,

 

Ryan "in need of help" Smith

 

code is below.

<?

//Get products database for reference on this page

$cat_id = $_GET["cat_id"];

$query = "SELECT * FROM tblProducts WHERE cat_id='".$cat_id."'";

$rsPrimary = mysql_query($query)

or die ("Query '$query' failed with error message: \"" . mysql_error () . '"');

$num=mysql_numrows($rsPrimary);

mysql_close();

 

// Check for the proceed button click, and if so, go validate the order

if ($_REQUEST["navigate"]=="proceed"){

/** We need the user to have selected at least one item, so let's see what they've chosen **

*** by looping through the submitted Quantity fields **/

$strCart="";

$num2 = $num;

for ($iLoop=5; $iLoop <= $num2; $iLoop++) {

  $strThisQuantity=$_REQUEST["Quantity" . $iLoop];

  if ($strThisQuantity == "") $num2++;

  else

  if ($strThisQuantity>0)

  $strCart=$strCart . $strThisQuantity . ",";

}

 

if (strlen($strCart)==0){

// Nothing was selected, so simply redesiplay the page with an error

$strPageError="You did not select any items to buy. ";

$_SESSION["strCart"]="";

}

 

else  {

// Save the cart to the session object

$_SESSION["strCart"]=$strCart;

// Proceed to the view shopping basket screen

ob_end_flush();

redirect("viewBasket.php");

}

}

 

elseif ($_REQUEST["navigate"]=="back") {

ob_flush();

redirect("index.php");

}

 

// If we have a cart in the session, then we'll show the selected items here **

$strCart=$_SESSION["strCart"];

 

?>

<?

require_once 'include/header.php';

?>

  <div id="center"><!-- Start of Center -->

<? echo $strPageError; ?>

<form action="buildOrder.php" method="POST" name="mainForm">

<input type="hidden" name="navigate" value="" />

          <h2>All Products</h2>

            <h3>Please select the quantity of the product and add to your cart.</h3>

            <div style="height:15px; width:100%; background:url(../images/circles.png) repeat-x; margin-top:-10px;"></div>

<table width="100%" class="formTable" >

<?

//Display a table row for each product in database

$i=0;

while ($i < $num) {

$strProductId = mysql_result($rsPrimary,$i,"ProductId");

$strImageId = "00" . $strProductId;

$strPrice = mysql_result($rsPrimary,$i,"Price");

echo "<tr>";

echo "<td rowspan=\"2\" align=\"center\"><a href=\"productDetail.php?ProductId=".mysql_result($rsPrimary,$i,"ProductId")."\"><img border=\"0\" src=\"images/product/" . mysql_result($rsPrimary,$i,"pd_thumbnail") ."\"</a></td>";

echo "<td width=\"350px\" align=\"left\"><h3><a href=\"productDetail.php?ProductId=".mysql_result($rsPrimary,$i,"ProductId")."\"><span style=\"color:#285488;\">" . mysql_result($rsPrimary,$i,"pd_name") . " - view product</a></h3> </span></td>";

echo "<td></td>";

echo "<td align=\"right\"><span style=\"color:#285488;\"><h3>£" . number_format($strPrice,2) . "</h3></span></td>";

 

echo "</tr>";

echo "<tr>";

$desc = mysql_result($rsPrimary,$i,"Description");

$description = substr($desc,1,120);

echo "<td align=\"left\">" . $description . ".....</td>";

echo "<td></td>";

echo "<td valign=\"right\" width=\"20px\">";

echo "<select name=\"Quantity" . $strProductId . "\"";

echo " size=\"1\">";

echo "<option value=\"0\">0</option>";

for ($iLoop=1; $iLoop <= 5; $iLoop++) {

$strThisItem=$iLoop . " of " . $strProductId;

echo "<option value=\"" . $strThisItem . "\"";

// If this is in our cart, show it selected

if(strstr($strCart,trim($strThisItem))) 

echo " SELECTED";

echo ">" . $iLoop . "</option>";

 

}

echo "</select></td>";

 

echo "<td align=\"left\"><a href=\"javascript:submitForm('mainForm','proceed');\"><img src=\"images/001_47.png\" border=\"0\"></a></td>";

echo "</tr>";

echo "<tr><td colspan=\"4\" style=\"border-bottom:1px solid #ccc;\"> </td></tr>";

$i++;

}

?>

</table>

</form>

</div>

 

 

 

<?php require_once 'include/footer.php';

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/181235-products-wont-add-to-my-database/
Share on other sites

  • 2 weeks later...
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.