RE: [PHP] problem transferring a variable using POST

2003-10-09 Thread Jay Blanchard
[snip]
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
[/snip]

There is your cluedouble quotes in your last example, but single
quotes in your query. To be verbose...

$sql = UPDATE wo SET status = 1 WHERE ticket = ' .
$HTTP_POST_VARS['ticketed'] . ' ;

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] problem transferring a variable using POST

2003-10-09 Thread Bertrand Moulard
you might try to do some processing on the value
get the HTTP_POST_VARS[...], put it in a variable and see its type
(gettype()). Might give you some hints.

-Original Message-
From: Davy Campano [mailto:[EMAIL PROTECTED]
Sent: 09 October 2003 16:57
To: [EMAIL PROTECTED]
Subject: [PHP] problem transferring a variable using POST


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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] problem transferring a variable using POST

2003-10-09 Thread Tom Rogers
Hi,

Friday, October 10, 2003, 1:56:43 AM, you wrote:
DC I am having a problem with a form.  I am trying to have a form pass a
DC variable so that I can update an item.  I think the problem is that the
DC variable (ticketed) is being read as text instead of a number.  These
DC are the tests I have run.  
 
DC This statement works:
DC $sql = 'UPDATE wo SET status = 1 WHERE ticket = 1'
 
DC This statement does not:
DC $sql = 'UPDATE wo SET status = 1 WHERE ticket =
DC $HTTP_POST_VARS[ticketed]'
 
DC Any suggestions...
 
DC If I do echo $HTTP_POST_VARS[ticketed]; 
DC It returns a 1

if you put variables in the string you need to use double quotes to get PHP to
do the substitution or get out of the string and use the dot operator.

$sql = UPDATE wo SET status = 1 WHERE ticket = $HTTP_POST_VARS[ticketed];
$sql = 'UPDATE wo SET status = 1 WHERE ticket = '.$HTTP_POST_VARS[ticketed];

The other good habit is to put the value in single quotes:

$sql = UPDATE wo SET status = 1 WHERE ticket = '$HTTP_POST_VARS[ticketed]';
$sql = UPDATE wo SET status = 1 WHERE ticket = '.$HTTP_POST_VARS[ticketed].';

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] problem transferring a variable using POST

2003-10-09 Thread Chris W. Parker
Davy Campano mailto:[EMAIL PROTECTED]
on Thursday, October 09, 2003 8:57 AM said:

 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

First of all you should be using $_POST and not $HTTP_POST_VARS (that is
of course if your version of php supports it).

Secondly, it's not working because (1) you are wrapping the sql
statement in single quotes which does not evaluate variables, it's a
string literal. You should change all those ' to , and (2) arrays are
treated differently than regular variables inside a string. They MUST be
wrapped with { } to be evaluated.

Third, it's a bad practice to not properly quote your array references.
In other words, the word ticketed should have single quotes around it.

Applying all these things your line should look like this:

$sql = UPDATE wo SET status = 1 WHERE ticket = {$_POST['ticketed']};


hth.
chris.

p.s. it's a Very Bad Idea(tm) to grab data directly from $_GET or $_POST
and put it to work before doing any validation on it.

p.p.s. I'm not positive about this but I'd be willing to bet that every
value gathered from $_GET or $_POST is considered a string and not
numeric. Think about it, how would $_POST know that ticketed is meant
to be an integer or a string?


-- 
Don't like reformatting your Outlook replies? Now there's relief!
http://home.in.tum.de/~jain/software/outlook-quotefix/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] problem transferring a variable using POST

2003-10-09 Thread Bertrand Moulard
Applying all these things your line should look like this:

$sql = UPDATE wo SET status = 1 WHERE ticket = {$_POST['ticketed']};

$_POST['ticketed'] : this is not an array but value isn't it ?

.b

-Original Message-
From: Chris W. Parker [mailto:[EMAIL PROTECTED]
Sent: 09 October 2003 17:08
To: Davy Campano; [EMAIL PROTECTED]
Subject: RE: [PHP] problem transferring a variable using POST


Davy Campano mailto:[EMAIL PROTECTED]
on Thursday, October 09, 2003 8:57 AM said:

 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

First of all you should be using $_POST and not $HTTP_POST_VARS (that is
of course if your version of php supports it).

Secondly, it's not working because (1) you are wrapping the sql
statement in single quotes which does not evaluate variables, it's a
string literal. You should change all those ' to , and (2) arrays are
treated differently than regular variables inside a string. They MUST be
wrapped with { } to be evaluated.

Third, it's a bad practice to not properly quote your array references.
In other words, the word ticketed should have single quotes around it.

Applying all these things your line should look like this:

$sql = UPDATE wo SET status = 1 WHERE ticket = {$_POST['ticketed']};


hth.
chris.

p.s. it's a Very Bad Idea(tm) to grab data directly from $_GET or $_POST
and put it to work before doing any validation on it.

p.p.s. I'm not positive about this but I'd be willing to bet that every
value gathered from $_GET or $_POST is considered a string and not
numeric. Think about it, how would $_POST know that ticketed is meant
to be an integer or a string?


-- 
Don't like reformatting your Outlook replies? Now there's relief!
http://home.in.tum.de/~jain/software/outlook-quotefix/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] problem transferring a variable using POST

2003-10-09 Thread Chris W. Parker
Bertrand Moulard mailto:[EMAIL PROTECTED]
on Thursday, October 09, 2003 9:20 AM said:

 $_POST['ticketed'] : this is not an array but value isn't it ?

Try print_r($_POST); and see what you get.


c.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] problem transferring a variable using POST

2003-10-09 Thread Bertrand Moulard
fair enough, $_POST is an array, but what about $_POST['ticketed'] ? Just
want to make sure about this {} thingie

.b

-Original Message-
From: Chris W. Parker [mailto:[EMAIL PROTECTED]
Sent: 09 October 2003 17:22
To: Bertrand Moulard; Davy Campano; [EMAIL PROTECTED]
Subject: RE: [PHP] problem transferring a variable using POST


Bertrand Moulard mailto:[EMAIL PROTECTED]
on Thursday, October 09, 2003 9:20 AM said:

 $_POST['ticketed'] : this is not an array but value isn't it ?

Try print_r($_POST); and see what you get.


c.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] problem transferring a variable using POST

2003-10-09 Thread Ford, Mike [LSS]
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: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] problem transferring a variable using POST

2003-10-09 Thread Chris W. Parker
Bertrand Moulard mailto:[EMAIL PROTECTED]
on Thursday, October 09, 2003 9:24 AM said:

 fair enough, $_POST is an array, but what about $_POST['ticketed'] ?
 Just want to make sure about this {} thingie

?php

echo This is the password $_POST['password'];
echo This is THE password {$_POST['password']};

?

The output of this page is the following:


Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING in
/home/cparker/public_html/oop/loginp.php on line 30

It's choking on the first echo statement.

Does that make sense now?



chris.

-- 
Don't like reformatting your Outlook replies? Now there's relief!
http://home.in.tum.de/~jain/software/outlook-quotefix/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] problem transferring a variable using POST

2003-10-09 Thread Bertrand Moulard
it does, thanks

-Original Message-
From: Chris W. Parker [mailto:[EMAIL PROTECTED]
Sent: 09 October 2003 17:28
To: Bertrand Moulard; Davy Campano; [EMAIL PROTECTED]
Subject: RE: [PHP] problem transferring a variable using POST


Bertrand Moulard mailto:[EMAIL PROTECTED]
on Thursday, October 09, 2003 9:24 AM said:

 fair enough, $_POST is an array, but what about $_POST['ticketed'] ?
 Just want to make sure about this {} thingie

?php

echo This is the password $_POST['password'];
echo This is THE password {$_POST['password']};

?

The output of this page is the following:


Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING in
/home/cparker/public_html/oop/loginp.php on line 30

It's choking on the first echo statement.

Does that make sense now?



chris.

-- 
Don't like reformatting your Outlook replies? Now there's relief!
http://home.in.tum.de/~jain/software/outlook-quotefix/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php