Jump to content

PLEASE HELP ME !! stuck on hidden values


ali_2kool2002

Recommended Posts

Hi im using a while loop to go through my query from the database. I get a product id and store it to the variable  using this line $productId = $results['productId']; I then try printing it on screen the value and comes up with 1, 2, 3, 4, which is correct but when i just enter it in the hidden input value it just only sends the value 4 which is the last value to the handeling form... If anyone can help or is on msn messenger i could send the files as im new to this im not sure how to send files here so add me plz [email protected] (sorry about the name ,,,lol only msn addy i hv)

 

 

HOPE SOME1 OUT THERE CAN HELP ME ,,,

cheers

 

 

 

 

 

 

 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?
//connect to the DB
session_start();

require_once('mysql_connect.php');
$display_block = "<h1>PRODUCTS - Product Detail</h1>";

//validate item
$get_item = "select c.catId as catId, c.cat_name, p.productId,p.productName, p.price, p.productDescription, p.image from product as p left join 
category as c on c.catId = p.catId";

$get_item_res = mysql_query($get_item) or die(mysql_error());

if ($get_item_res) {



echo '<table align="center" cellspacing="1" cellpadding="5">
<tr><td align="left"><b>Cat Id</b></td>
<td align="center"><b>  Category Name</b></td>
<td align="center"><b>  Item Name</b></td>
<td align="center"><b>  Item Description</b></td>
<td align="center"><b>  Images</b></td>
<td align="center"><b>  Price</b></td>
</tr></table>';

while ($results = mysql_fetch_array($get_item_res, MYSQL_ASSOC))
      { 
//variable to hold image file name from array
extract($results);
$image = $results['image']  ;	
//variable to hold productId from array
$productId = $results['productId'];


echo $productId;
echo '<form method = post action="addtocart.php">';									

echo'<INPUT TYPE ="submit" name = "submit" value = "Add to Cart" maxlength "50">
<input type="hidden" name="sel_item_id" value="'.$productId.'">';


}
//	echo '</table>';
//echo $display_block;
} else 
{ // If it did not run OK.
echo '<p>The current products could not be retrieved.
We apologize for any inconvenience.</p>'; 
echo '<p>' . mysql_error() . '</p>';
}
mysql_close(); 


?>


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>



Link to comment
https://forums.phpfreaks.com/topic/38158-please-help-me-stuck-on-hidden-values/
Share on other sites

It's because each time the while statement executes, it writes over the previous value of $_POST['sel_item_id'].  You need to change this line:

<input type="hidden" name="sel_item_id" value="'.$productId.'">';

 

To this:

<input type="hidden" name="sel_item_id[]" value="'.$productId.'">';

 

Now, each name will be different.

Hi iv changed that code to the array as

 

<input type="hidden" name="sel_item_id[]" value="'.$productId.'">';

 

but now i have an error in my handling form saying >>

ArrayUnknown column 'Array' in 'where clause'

 

p.s. THANKS FOR UR REPLY BEFORE REALLY REALLY APPRECIATE IT ,, UR KEWL  MATE,,!! THANKS :);D

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
session_start();
$PHPSESSID = session_id(); 
require_once('mysql_connect.php');
//if (isset($_POST['submitted'])) 
if ($_POST['sel_item_id'] != "") 
{
echo $x = $_POST['sel_item_id'];


$get_iteminfo = "select productName from product where productId=$_POST[sel_item_id]";
$get_iteminfo_res = mysql_query($get_iteminfo) or die(mysql_error());

if (mysql_num_rows($get_iteminfo_res) < 1) {
   	    //invalid id, send away
   	    echo "query failed";
	//header("Location: homepage.php");
   	    exit;
}else {
   	    //get info
	 	    $item_title =  mysql_result($get_iteminfo_res,0,'productName');
	echo $item_title;
	//add info to cart table
	$id = 0;

   	    $addtocart = "insert into store_shoppertrack values ('$id', '$PHPSESSID', '$_POST[sel_item_id]', '2', now())";
	$id= 1 + $id;
	$addquery = mysql_query($addtocart) or die (mysql_error());


	//header("Location: showcart.php");
  	    exit;
} }else {
   echo "//send them somewhere else";
  //  header("Location: homepage.php");
    exit;
}

?>


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

</body>
</html>

Hi iv tried ur second  example usings loops but cuz im so new at php how do i do a loop in php cuz i need 2 know the size of the array that u have mentioned and then i could do a for loop,not sure sorry how to code the loops mate, sori hope u can help me more from what u mentioned using the 2 loops...thanks

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.