RE: [PHP] problem transferring a variable using POST
| From: | Ford, Mike [LSS] | Date: | Thu, 09 Oct 2003 16:09:38 +0000 |
| Subject: | RE: [PHP] problem transferring a variable using POST | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-165627@lists.php.net to get a copy of this message | ||
On 09 October 2003 16:57, Davy Campano wrote:
> I am having a problem with a form. I am trying to have a form pass a
> variable so that I can update an item. I think the problem
> is that the
> variable (ticketed) is being read as text instead of a number. These
> are the tests I have run.
>
> This statement works:
> $sql = 'UPDATE wo SET status = 1 WHERE ticket = 1'
>
> This statement does not:
> $sql = 'UPDATE wo SET status = 1 WHERE ticket =
> $HTTP_POST_VARS[ticketed]'
>
> Any suggestions...
>
> If I do "echo "$HTTP_POST_VARS[ticketed]";
> It returns a 1
variables are not interpolated in single-quoted strings -- you need double quotes in your assignment
statement, too:
$sql = "UPDATE wo SET status = 1 WHERE ticket = $HTTP_POST_VARS[ticketed]";
or (my preference):
$sql = "UPDATE wo SET status = 1 WHERE ticket =
{$HTTP_POST_VARS['ticketed']}";
(And, of course, if your PHP is 4.2.0 or later, you should probably prefer to use $_POST rather than
$HTTP_POST_VARS.)
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211