PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
lmh85
Forum Commoner
Posts: 49 Joined: Sat Oct 28, 2006 10:49 am
Post
by lmh85 » Sun Oct 29, 2006 7:57 pm
hope anyone can help me in it.
here it goes. I had created a set of buttons by setting array in their names such as
Code: Select all
using a for loop..
<input type=\"submit\"value=\"Add To Cart\" class=\"btnListAdd\"name=\"btnAdd[$rowPdtCount[0]]\" id=\"btnAdd[$rowPdtCount[0]]\" onClick=\"addToCart($rowPdtCount[0]);\">
after which, i need to get the button clicked event but i hit an error.
Code: Select all
foreach ($_POST['btnAdd'] as $key => $value){
if(isset($_POST['btnAdd[$key]'])){
..blabla..
}
and i gotten nothing. is it how its suppose to be done?sorry, a real noob here.
nickvd
DevNet Resident
Posts: 1027 Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:
Post
by nickvd » Sun Oct 29, 2006 8:29 pm
what does the html code look like after php has outputted it? (use the view source option and copy/paste back here...)
lmh85
Forum Commoner
Posts: 49 Joined: Sat Oct 28, 2006 10:49 am
Post
by lmh85 » Sun Oct 29, 2006 8:40 pm
nickvd wrote: what does the html code look like after php has outputted it? (use the view source option and copy/paste back here...)
Code: Select all
<table width="100%" cellspacing="8"><tr><td><hr><table border="0"><tr><td class="bodyTextNorm" width="75%"><a href="javascript:void(0)" onclick="popupDetails(1)" class="ahref">DF002001<a href="javascript:void(0)" onclick="popupDetails(1)" class="ahref"> <b>product details</b></a></td><td class="bodyTextNorm" width="12%"><div class="bodyText">Qty : <input type="text" name="txtQty" value="0" size="1" maxlength="2" class="bodyTextNorm"></div></td><td width="13%" align="right"><input type="submit"value="Add To Cart" class="btnListAdd"name="btnAdd[DF002001]" id="btnAdd[DF002001]"></td></tr></table><hr></td></tr><tr><td><table border="0"><tr><td class="bodyTextNorm" width="75%"><a href="javascript:void(0)" onclick="popupDetails(1)" class="ahref">DF002003<a href="javascript:void(0)" onclick="popupDetails(1)" class="ahref"> <b>product details</b></a></td><td class="bodyTextNorm" width="12%"><div class="bodyText">Qty : <input type="text" name="txtQty" value="0" size="1" maxlength="2" class="bodyTextNorm"></div></td><td width="13%" align="right"><input type="submit"value="Add To Cart" class="btnListAdd"name="btnAdd[DF002003]" id="btnAdd[DF002003]"></td></tr></table><hr></td></tr>
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Mon Oct 30, 2006 2:29 am
i think you need to use onclick event of javascript on button
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Oct 30, 2006 3:17 am
lmh85 wrote: but i hit an error.
Is it a secret error message or can you share it with us?
Try
Code: Select all
echo '<pre>'; print_r($_POST); echo "</pre>\n";right before your foreach loop. Does the array contain the elements/values you're expecting?
lmh85
Forum Commoner
Posts: 49 Joined: Sat Oct 28, 2006 10:49 am
Post
by lmh85 » Mon Oct 30, 2006 7:39 am
volka wrote: lmh85 wrote: but i hit an error.
Is it a secret error message or can you share it with us?
Try
Code: Select all
echo '<pre>'; print_r($_POST); echo "</pre>\n";right before your foreach loop. Does the array contain the elements/values you're expecting?
these buttons is created when i pop information out of the database. there's error on my foreach. Because there's nothing found. I need to put the data into $_SESSION.. is it possible to be done in javascript? or is there anyway i can do it in php by detecting the button click?
lmh85
Forum Commoner
Posts: 49 Joined: Sat Oct 28, 2006 10:49 am
Post
by lmh85 » Mon Oct 30, 2006 7:42 am
volka wrote: lmh85 wrote: but i hit an error.
Is it a secret error message or can you share it with us?
Try
Code: Select all
echo '<pre>'; print_r($_POST); echo "</pre>\n";right before your foreach loop. Does the array contain the elements/values you're expecting?
hi there, i had tried echoing out. There's nothing in the array. it shows..
Code: Select all
Array
(
)
Warning: Invalid argument supplied for foreach() in C:\www\prdts.php on line 3
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Oct 30, 2006 7:47 am
lmh85 wrote: Code: Select all
<table width="100%" cellspacing="8"><tr><td><hr><table border="0"><tr><td class="bodyTextNorm" width="75%"><a href="javascript:void(0)" onclick="popupDetails(1)" class="ahref">DF002001<a href="javascript:void(0)" onclick="popupDetails(1)" class="ahref"> <b>product details</b></a></td><td class="bodyTextNorm" width="12%"><div class="bodyText">Qty : <input type="text" name="txtQty" value="0" size="1" maxlength="2" class="bodyTextNorm"></div></td><td width="13%" align="right"><input type="submit"value="Add To Cart" class="btnListAdd"name="btnAdd[DF002001]" id="btnAdd[DF002001]"></td></tr></table><hr></td></tr><tr><td><table border="0"><tr><td class="bodyTextNorm" width="75%"><a href="javascript:void(0)" onclick="popupDetails(1)" class="ahref">DF002003<a href="javascript:void(0)" onclick="popupDetails(1)" class="ahref"> <b>product details</b></a></td><td class="bodyTextNorm" width="12%"><div class="bodyText">Qty : <input type="text" name="txtQty" value="0" size="1" maxlength="2" class="bodyTextNorm"></div></td><td width="13%" align="right"><input type="submit"value="Add To Cart" class="btnListAdd"name="btnAdd[DF002003]" id="btnAdd[DF002003]"></td></tr></table><hr></td></tr>Is there a form element? Or how do you set the POST method?
lmh85
Forum Commoner
Posts: 49 Joined: Sat Oct 28, 2006 10:49 am
Post
by lmh85 » Mon Oct 30, 2006 7:55 am
volka wrote: lmh85 wrote: Code: Select all
<table width="100%" cellspacing="8"><tr><td><hr><table border="0"><tr><td class="bodyTextNorm" width="75%"><a href="javascript:void(0)" onclick="popupDetails(1)" class="ahref">DF002001<a href="javascript:void(0)" onclick="popupDetails(1)" class="ahref"> <b>product details</b></a></td><td class="bodyTextNorm" width="12%"><div class="bodyText">Qty : <input type="text" name="txtQty" value="0" size="1" maxlength="2" class="bodyTextNorm"></div></td><td width="13%" align="right"><input type="submit"value="Add To Cart" class="btnListAdd"name="btnAdd[DF002001]" id="btnAdd[DF002001]"></td></tr></table><hr></td></tr><tr><td><table border="0"><tr><td class="bodyTextNorm" width="75%"><a href="javascript:void(0)" onclick="popupDetails(1)" class="ahref">DF002003<a href="javascript:void(0)" onclick="popupDetails(1)" class="ahref"> <b>product details</b></a></td><td class="bodyTextNorm" width="12%"><div class="bodyText">Qty : <input type="text" name="txtQty" value="0" size="1" maxlength="2" class="bodyTextNorm"></div></td><td width="13%" align="right"><input type="submit"value="Add To Cart" class="btnListAdd"name="btnAdd[DF002003]" id="btnAdd[DF002003]"></td></tr></table><hr></td></tr>Is there a form element? Or how do you set the POST method?
oops.. there's no form element in this page. sorry, may i know what do u mean by setting the POST method?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Oct 30, 2006 8:07 am
You're using $_POST in your php script.
http://www.php.net/manual/en/reserved.v ... quote]HTTP POST variables: $_POST
...
An associative array of variables
passed to the current script via the HTTP POST method. [/quote]The default is GET which does not pop up in $_POST. You must instruct the client that it shall pass the parameters via POST.
Code: Select all
<form method="post" action="xyz.php">
lmh85
Forum Commoner
Posts: 49 Joined: Sat Oct 28, 2006 10:49 am
Post
by lmh85 » Mon Oct 30, 2006 8:09 am
The default is GET which does not pop up in $_POST. You must instruct the client that it shall pass the parameters via POST.
Code: Select all
<form method="post" action="xyz.php">[/quote]
i had added form tag but it still can't work..
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Oct 30, 2006 8:13 am
current code?
(sorry, I'm still no clairvoyant)
lmh85
Forum Commoner
Posts: 49 Joined: Sat Oct 28, 2006 10:49 am
Post
by lmh85 » Mon Oct 30, 2006 8:16 am
i had added the form tag and it works now!
i added the form tag wrongly.. thanks thanks!