Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programming a Basket in a shop

Status
Not open for further replies.

axmug

Programmer
Oct 13, 2003
34
ES
I'm doing a basket of a shop and I don't know how to modify the number of products that are in the basket if the user change the number of someone.

The problem is that when the user modify the number of units of a product I don't know which product has been modified (first,second,third...) and I can't update the database table where are the products stored.

I have been typing the following lines but they don't work:

$qry4=mysql_query("select numprodorders from orders where idpub='$rw[idprod]'");
$rw4=mysql_fetch_array($qry4);
echo &quot;<td align=\&quot;center\&quot; bgcolor=\&quot;#ccddee\&quot;><input type=\&quot;text\&quot; name=\&quot;cant[]\&quot; size=\&quot;2\&quot; value=\&quot;$rw4[numprodorders]\&quot;></td>&quot;;

The lines of above are for showing the products that are in the basket, the following are the lines for the button Update that is to update the number of product units:

echo &quot;<form method=\&quot;post\&quot; action=\&quot;main.php?name=Shop&file=update\&quot;;&quot;;
echo &quot; <td align=center>&quot;;
echo &quot; <input type=\&quot;submit\&quot; name=\&quot;update\&quot; value=\&quot;Update\&quot;>&quot;;
echo &quot; </td>&quot;;

I would like how to solve this problem.

Thank you.
 
I'm not 100% sure what u'r asking but have you tried changing
Code:
where idpub='$rw[idprod]'&quot;);

to


where idpub='.$rw[idprod].'&quot;);


Which lines don't work exactly and how are they not working??
 
The problem is the value of the array cant[]. I have two products in the basket and I decide to change the number of units of the second product. If I click the button update the file update runs due to the line

echo &quot;<form method=\&quot;post\&quot; action=\&quot;main.php?name=Shop&file=update\&quot;;&quot;;

In this file I have the following:

$t=count($_POST['cant']);
echo $t;

The result after executing it is a 0 in the screen, so it's not possible because I modified the number of units of the second product typing 2 in his unit box.

What I want to do is to save in a variable the values of the units of all products modified by the user and I can't do it. How can I do it?

Thanks.
 
There is a trick with PHP and form field naming that might come in handy.

Assume you have a form like

Code:
<html><body><form method=&quot;POST&quot; action=&quot;test_formnames.php&quot;>
<table>
	<tr><th>Description</th><th>Quantity</th></tr>
	<tr>
		<td>Some catalog item</td>
		<td><input type=text name=&quot;amount[12345]&quot; value=&quot;3&quot;></td>
	</tr>
	<tr>
		<td>Another catalog item</td>
		<td><input type=text name=&quot;amount[54321]&quot; value=&quot;4&quot;></td>
	</tr>
</table><input type=&quot;submit&quot;></form></body></html>

(Pay particular attention to the names of the text inputs)

If the form is submitted, $_POST['amount'] will itself be an array in PHP. The element at array key &quot;12345&quot; will contain the value of the first input, the element at &quot;54321&quot; will contain the value for the second.

If those element keys match inventory numbers from your online catalog, you can match user-selected amounts to a particular item in the catalog.

If you need to also address the values of those inputs from JavaScript, you will have to add the attribute 'id=&quot;somename&quot;' to each in put and refer to the inputs by those IDs instead of names.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top