Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 13th, 2004, 10:30 AM
Authorized User
 
Join Date: Dec 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Form problem

Hi Guys,

In a Form I'm using the following field;

<input type="Text" name="quant<? echo $intID; ?>" maxlength="2" size="2" value="<? echo $intQuant; ?>">

it is used in a shopping cart, so more than one of these can exist in the form.
in ASP i've previously used 'request.form("quant"&intID&"")' to retreive the form value. however, in PHP i haven't had any success yet.

Could someone help me out?

Thanks

HammR

 
Old March 13th, 2004, 11:46 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Ah... you need $_GET and $_POST

page1.php

<form method=post action=page2.php>
<input type="Text" name="quant<?php echo $intID; ?>" maxlength="2" size="2" value="<?php echo $intQuant; ?>">
</form>

page2.php

<?php
if(isset($_POST['quant' . $intID])) $textbox = $_POST['quant' . $intID];
?>

This example uses $_POST

When the form method is GET then use $_GET

http://www.php.net/variables.predefined

HTH,

----------
---Snib---
----------
 
Old March 17th, 2004, 01:27 PM
Authorized User
 
Join Date: Dec 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Snib,

However, the code you provided is working when using PHP version 4.3.4 (on a Windows machine), but does not work on PHP 4.0.6 (on a linuxserver).
any solution for this? besides upgrading..;)

Thanks!

 
Old March 17th, 2004, 02:05 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Hmm... try replacing $_GET and $_POST with $HTTP_GET_VARS and $HTTP_POST_VARS

Not sure this will work, but its worth a try!:)

----------
---Snib---
----------

<><
 
Old March 17th, 2004, 09:14 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It will work as long as you guarantee that HTTP_xxx_VARS is in scope. These variables are *NOT* superglobal arrays; that is, they need to be explicitly imported into function scope if you're using them within a function.

You can do this via the global keyword:

function foo()
{
    global $HTTP_POST_VARS;

    echo $HTTP_POST_VARS['quant'];
}


Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Form Problem prasanta2expert C# 1 September 24th, 2007 08:57 PM
Upload.Form problem barkerl Classic ASP Basics 1 January 22nd, 2007 06:06 AM
Sum on a form Problem Corey Access 1 November 9th, 2005 05:43 PM
form problem nulogix PHP How-To 4 June 16th, 2004 12:08 PM
Form problem tonyh Beginning VB 6 4 October 28th, 2003 03:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.