Re: undefined variable
| From: | Smart Software | Date: | Sun, 30 Apr 2006 20:43:57 +0000 |
| Subject: | Re: undefined variable | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-235164@lists.php.net to get a copy of this message | ||
isset always returns 0
i create dynamic textbox called quantity0, textbox1, textbox3.......
then i a, trying to get the content of the textbox but it is always 0.
as you can see, i tried the suggestions but it still dont work.
is there something iam doing wroing? why is the textbox always 0?
<table width="700">
<? $query1 = mysql_query("SELECT * FROM products where product_group='$cat'
order by position");
$counter = 0;
while ($rowType = mysql_fetch_array($query1))
{
$textbox="quantity";
$textbox= "$textbox$counter"; //variable is set to quantity0, quantity1,
quantity2 etc
?>
<td width="30%">New row number: <? echo $counter; ?></td>
<td width="30%">name of textbox: <? echo $textbox; ?></td>
<? //below the textbox will be created?>
<td width="10%"><input id="<? $textbox ?>" name="<?
$textbox ?>"
type="text" value="1" size="1" maxlength="3"></td>
<?
//get content of textbox
$q = isset($_REQUEST['$textbox']) ? $_REQUEST['$textbox'] : 0;
?>
<td width="10%"> <a href=" <? echo
"products.php?quantity=$q"; ?>"
</a>TEST</td>
<td width="20%"> <? echo "content of textbox: $q"; ?> </td>
</tr>
<?
$counter++;
}
?>
</table>
""Richard Lynch"" <ceo@l-i-e.com> schreef in bericht
news:53414.67.184.121.112.1146346993.squirrel@www.l-i-e.com...
> On Sat, April 29, 2006 5:42 am, Smart Software wrote:
>> code below shows all records from products table with an textbox and
>> an
>> order button for each record
>
>> How can i add the content of the textbox?
>> i tried this:
>> <td width="40%"> <a href="<? echo
>>
>> "products.php?cat=$cat&quantity=$quantity&toevoegen=1&id=$rowType[7]";
>> ?>"><img src="images/bestel1.gif"
>> border="0"></a></td>
>>
>> but all i get is an error telling me there is a undefined varable
>
> You probably are following some kind of tutorial that assumes
> "register_globals" is "on" -- or you are simply used to that
> environment.
>
> So when you try to use $quantity, it's not defined.
>
> The value you want is in $_REQUEST['quantity'];
>
> You should do something like this:
>
> <?php
> //Get data from REQUEST:
> $quantity = isset($_REQUEST['quantity']) ? $_REQUEST['quantity'] : 0;
> //Force valid data:
> $quantity = (int) $quantity;
> //rest of script here.
> ?>
>
> --
> Like Music?
> http://l-i-e.com/artists.htm