Jump to content

Retrieve product_id


joinx

Recommended Posts

HI all..I am doing an ecommerce site..

After displaying my list of product...i'm not able to retrieve that product id to display its details and add it to shopping cart..

here is my code...how should i proceed...thnx

This is my product.php(display list of product based on category)..image not displaying...

<?php require_once('../Connections/JaceyConn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $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;
  }
  }
$colname_brand = "-1";
if (isset($_GET['category_id'])) {
  $colname_brand = $_GET['category_id'];
}
mysql_select_db($database_JaceyConn, $JaceyConn);
$query_brand = sprintf("SELECT product_id, product_name, product_price, product_image FROM product WHERE category_id = %s", GetSQLValueString($colname_brand, "int"));
$brand = mysql_query($query_brand, $JaceyConn) or die(mysql_error());
$row_brand = mysql_fetch_assoc($brand);
$totalRows_brand = mysql_num_rows($brand);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta name="description" content="description"/>
<meta name="keywords" content="keywords"/> 
<meta name="author" content="author"/> 
<link rel="stylesheet" type="text/css" href="bntemplate590/images590/default.css"/>
<title>Jacey</title>
<style type="text/css">
<!--
body,td,th {
font-size: 9pt;
}
-->
/* Tabs Menu */

    #tabsE {
      float:left;
      width:100%;
      font-size:70%;
      line-height:normal;

      }
    #tabsE ul {
margin:0;
padding:10px 10px 0 50px;
list-style:none;
      }
    #tabsE li {
      display:inline;
      margin:0;
      padding:0;
      }
    #tabsE a {
      float:left;
      background:url(../Tab/tableftE.gif) no-repeat left top;
      margin:0;
      padding:0 0 0 4px;
      text-decoration:none;
      }
    #tabsE a span {
float:left;
display:block;
padding:5px 15px 4px 6px;
color:#FFF;
background-image: url(../Tab/tabrightE.gif);
background-repeat: no-repeat;
background-position: right top;
      }
    /* Commented Backslash Hack hides rule from IE5-Mac \*/
    #tabsE a span {float:none;}
    /* End IE5-Mac hack */
    #tabsE a:hover span {
      color:#FFF;
      }
    #tabsE a:hover {
      background-position:0% -42px;
      }
    #tabsE a:hover span {
      background-position:100% -42px;
      }  

.style5 {color: #FF0000}
</style>
</head>


<body>

<div class="main">

<div class="main_left">

<div class="header">
		<h1 align="center">Jacey Computers</h1>
  </div>

	<div class="link_menu">
		<a href="main.php" accesskey="1">Home</a>
		<a href="category.php" accesskey="2">Product</a>
		<a href="support.php" accesskey="3">Support & Help</a>
		<a href="contact.php" accesskey="4">Contact Us</a>		</div>

	<div class="content">
       
      
	 <p> </p>
	 <table align="center" border="2">
         <?php	


while($row = mysql_fetch_array($brand)) {?>
<?php $imageurl = $row['product_image'] ?>

<tr>
<td width="307">
<p><img src="<?php echo $imageurl; ?>" />
    <?php echo $row['product_name']."<br><font color=red>Price:</font>Rs".$row['product_price'];?></p>

  <a href="info.php?product_id=<?php echo $row['product_id'];?>">More Info</a>

<form name="form" action="showcart.php" method="POST">
<input name="product_id" type="hidden" value="%s"/>
<input type="submit" value="Add To cart">
<input type="hidden" name="MM_insert" value="form" />
</form>
</form></td>
</tr>

<?php } ?>

   </table>
    
         </div>



</div>
<div class="footer">
  <div align="center">© www.jacey.mu </div>
</div>
</div>
<br style="clear: both;" />

</body>

</html>

 

This is my info.php(display details of select product)..

<?php require_once('../Connections/JaceyConn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $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;
}
}

$colname_descrip = "-1";
if (isset($_GET['product_id'])) {
  $colname_descrip = $_GET['product_id'];
}
mysql_select_db($database_JaceyConn, $JaceyConn);
$query_descrip = sprintf("SELECT * FROM product WHERE product_id = %s", GetSQLValueString($colname_descrip, "int"));
$descrip = mysql_query($query_descrip, $JaceyConn) or die(mysql_error());
$row_descrip = mysql_fetch_assoc($descrip);
$totalRows_descrip = mysql_num_rows($descrip);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta name="description" content="description"/>
<meta name="keywords" content="keywords"/> 
<meta name="author" content="author"/> 
<link rel="stylesheet" type="text/css" href="bntemplate590/images590/default.css"/>
<title>Jacey</title>
<style type="text/css">
<!--
.style4 {font-size: 14pt}
body,td,th {
font-size: 9pt;
}
-->
</style></head>

<body>

<div class="main">

<div class="main_left">

<div class="header">
		<h1 align="center">Jacey Computers</h1>
  </div>

	<div class="link_menu">
		<a href="main.php" accesskey="1">Home</a>
		<a href="category.php" accesskey="2">Product</a>
		<a href="support.php" accesskey="3">Support & Help</a>
		<a href="contact.php" accesskey="4">Contact Us</a>		</div>

	<div class="content">
		       
      
	 <p> </p>
	 <table align="center" border="2">
         <?php	


$row = mysql_fetch_array($descrip); ?>
<?php $imageurl = $row['product_image']; ?>

<tr>
<td width="307">
<p><img src="<?php echo $imageurl; ?>" />
    <?php echo $row['product_name']."<br><font color=red>Price:</font>Rs".$row['product_price'];?></p>



<form name="form" action="showcart.php" method="POST">
<input name="product_id" type="hidden" value="$pid"/>
<input type="submit" value="Add To cart">
<input type="hidden" name="MM_insert" value="form" />
</form>
</form>
</td>
</tr>
   </table>
   
            
  </div>
</div>

</div>
<div class="footer"></div>
</div>
<br style="clear: both;" />

</body>

</html>


 

Where the code for add to cart should be included?

Link to comment
https://forums.phpfreaks.com/topic/102991-retrieve-product_id/
Share on other sites

Your hidden field won't work because you're trying to set the value without surrounding the variable in php tags. Also, you're not specifying the value of the variable (as far as I can tell.)

 

Your code at the moment:

 

<input name="product_id" type="hidden" value="$pid"/>

 

What your code should probably look like:

 

<input name="product_id" type="hidden" value="<?php echo $pid; ?>"/>

 

Or maybe:

 

<input name="product_id" type="hidden" value="<?php echo $row['id']; ?>"/>

Link to comment
https://forums.phpfreaks.com/topic/102991-retrieve-product_id/#findComment-527619
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.