Jump to content

Submit not working


graham23s

Recommended Posts

Hi Guys,

 

i have this block of code i use to display products in an online shop:

 

 // display box for products //
$display_box =  "<form action=\"shoppingcart.php\" method=\"get\">\n";
$display_box =  "<div id=\"right\">\n";
$display_box .= "<div class=\"boxtop\">\n";
$display_box .= "</div>";
$display_box .= "<div class=\"box\">";
$display_box .= "<img src=\"images/image.gif\" alt=\"Product Image\" title=\"Product Image\" class=\"image\" />\n";
$display_box .= "<b>$product_name</b>";
$display_box .= "<br />";
$display_box .= "<br />";
$display_box .= "$product_description";
$display_box .= "<br />";
$display_box .= "<hr />";
$display_box .= "<input type=\"hidden\" name=\"productid\" value=\"$productid\" />";
$display_box .= "<input type=\"submit\" name=\"submit\" value=\"Add To Cart\" />";
$display_box .= "<hr />";
$display_box .= "<span class=\"price\">$2.99</span>";
$display_box .= "<br />";
$display_box .= "<hr />";
$display_box .= "<b>Quantity:</b>-";
$display_box .= "<select name=\"quantity\">";
$display_box .= "<option value=\"1\">1</option>";
$display_box .= "<option value=\"2\">2</option>";
$display_box .= "<option value=\"3\">3</option>";
$display_box .= "</select>";
$display_box .= "</div>\n";
$display_box .= "</div>\n";
$display_box .= "</div>\n";
$display_box .= "</form>\n"; 

 

the way it is above the button does forward you to the shoppingcart.php, but when i move it down a few lines it work, but then throws my css out of whack, is there anywhere specific i should put it?

 

heres the full page:

 

<?php
session_start();

include("inc/dbconnection.php");
include("inc/online.php");
include("inc/header.php");
include("inc/navigation.php");
?>
<?php
// get the id //
$categoryid = $_GET['id'];

// query the db //
$queryproduct = "SELECT * FROM `fcp_categories` WHERE `id`='$categoryid'";
$resultproduct = mysql_query($queryproduct) or die (mysql_error());
$row = mysql_fetch_array($resultproduct) or die (mysql_error());

// vars //
$catname = $row['categoryname'];

// set the rane //
$quantity = range(1,99);

// get and display all the products associated with this cat //
$queryproducts = "SELECT * FROM `fcp_products` WHERE `category_id`='$categoryid'";
$resultsproducts = mysql_query($queryproducts) or die (mysql_error());

// number of products //
$numproducts = mysql_num_rows($resultsproducts);

// standard header //
print("<div class=\"subheader\"><div id=\"title\">Category > <span class=\"blue\">$catname</span></div>We have <b>$numproducts</b> products in this category for you to browse.</div>");

//--------------------------------------------//

// need modulous to display them properly //
$i = 0;

// begin the table //
print("<table class=\"products_table\" align=\"center\" width=\"100%\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\">");

// start the while loop //
while ($rows = mysql_fetch_array($resultsproducts))
{

$productid = $rows['id'];
$product_name = $rows['product_name'];
$product_description = $rows['product_description'];

// display box for products //
$display_box =  "<form action=\"shoppingcart.php\" method=\"get\">\n";
$display_box =  "<div id=\"right\">\n";
$display_box .= "<div class=\"boxtop\">\n";
$display_box .= "</div>";
$display_box .= "<div class=\"box\">";
$display_box .= "<img src=\"images/image.gif\" alt=\"Product Image\" title=\"Product Image\" class=\"image\" />\n";
$display_box .= "<b>$product_name</b>";
$display_box .= "<br />";
$display_box .= "<br />";
$display_box .= "$product_description";
$display_box .= "<br />";
$display_box .= "<hr />";
$display_box .= "<input type=\"hidden\" name=\"productid\" value=\"$productid\" />";
$display_box .= "<input type=\"submit\" name=\"submit\" value=\"Add To Cart\" />";
$display_box .= "<hr />";
$display_box .= "<span class=\"price\">$2.99</span>";
$display_box .= "<br />";
$display_box .= "<hr />";
$display_box .= "<b>Quantity:</b>-";
$display_box .= "<select name=\"quantity\">";
$display_box .= "<option value=\"1\">1</option>";
$display_box .= "<option value=\"2\">2</option>";
$display_box .= "<option value=\"3\">3</option>";
$display_box .= "</select>";
$display_box .= "</div>\n";
$display_box .= "</div>\n";
$display_box .= "</div>\n";
$display_box .= "</form>\n"; 


if ($i==0) {  
     
print('<tr><td align="center">'.$display_box.'</td>');
     
} elseif ($i == 2) { 
       
print('<td align="center">'.$display_box.'</td></tr>');  
        
  } else {    
  
print('<td align="center">'.$display_box.'</td>');  
    
} 
     $i++; $i=$i % 2; // mod 2 gives you the remainder //   

} // end the while loop //

  // end the products tabel //
print("</tr>");
print("</table>"); 
?>
<?php
// include the footer //
include("inc/footer.php");
?>

 

thanks guys

 

Graham

Link to comment
Share on other sites

 $display_box =  "<form action=\"shoppingcart.php\" method=\"get\">\n";
$display_box =  "<div id=\"right\">\n";

 

Doesn't the second line over write the first? I think you need

 

 $display_box =  "<form action=\"shoppingcart.php\" method=\"get\">\n";
$display_box .=  "<div id=\"right\">\n";

 

 

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.