Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-28-2006, 04:22 AM   #1
Senior Member
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 9.2
Posts: 1,195

Rep: Reputation: 51
Incorrect PHP code is working, shoud I "fix" it?

I have the following line of HTML code:
<input type='hidden' name='flag' vflag='0'></form>
I meant to type "value='0'" instead of "vflag='0'" but it works despite my basic knowledge telling me it's incorrect code.
It works because the statements included in the following are all executed by PHP:
if(isset($_POST['flag']) && ($_POST['vflag']==0)) {
some code ;

Should I "fix" it?

Thank you for your help.
Old 04-28-2006, 05:12 AM   #2
Registered: May 2004
Location: Karlsruhe, Germany
Distribution: debian, gentoo, os x (darwin), ubuntu
Posts: 940

Rep: Reputation: 33
sure it works...
<input type='hidden' name='flag' vflag='0'>
would set $_POST['flag'] with no value, so
isset($_POST['flag']) will return true.
$_POST['vflag'] is not set, therfore equals to 0
to set $_POST['vflag'] = 0 you would want
<input type='hidden' name='flag' value='0'>
<input type='hidden' name='vflag' value='0'>

on top of that, you should fix it, as it is not valid xhtml, or html.
Old 04-28-2006, 09:49 AM   #3
Registered: Mar 2003
Location: Berkshire, England.
Distribution: SuSE 10.0
Posts: 299

Rep: Reputation: 32
Short answer: Yes. If you spot a coding bug, and you know how to fix it, you should do so. What possible reason could you have for not fixing it?

Also the PHP code seems to be confusing the field name too:
if(isset($_POST['flag']) && ($_POST['vflag']==0)) {
Is the field supposed to be called 'flag' or 'vflag'? Assuming they're both supposed to be referencing the same field, you should correct that as well as the html.
Old 04-28-2006, 01:10 PM   #4
Senior Member
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 9.2
Posts: 1,195

Original Poster
Rep: Reputation: 51
Thank you both. What i found confusing was that "vflag" not set did not return a value of 0 but a value of "".
Old 04-28-2006, 05:13 PM   #5
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
$_POST['vflag'] does not exist obviously, so an empty string ( "" ) is the value of $_POST['vflag']. If you then use it as an integer, it will be converted automatically to an integer of zero.
Old 04-28-2006, 10:28 PM   #6
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
To differentiate between "" and 0, use the triple-equals === for equality checks. This ensures that the types between the two operands are consistent, not merely equivalent in the course of evaluation. Example:
"" == 0 // returns true
"" === 0 // returns false
Also, whenever you find a bug, you should fix it. This practice improves not only maintainability, but also security. All security flaws are bugs, therefore less bugs means less security vulnerabilities.
Old 04-28-2006, 11:33 PM   #7
Senior Member
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 9.2
Posts: 1,195

Original Poster
Rep: Reputation: 51
Thank you all again, it's all valuable info.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
repquota (and edquota) report incorrect "used" blocks/inodes.. marcolof Linux - General 0 02-18-2005 10:26 AM
Get "530 Login incorrect." trying to FTP to Slackware 9.1 box. RichDawg Linux - Networking 1 07-22-2004 08:45 PM
Getting "530 Login incorrect" trying to ftp to slackware 9.1 box. RichDawg Linux - Newbie 0 07-22-2004 03:05 PM
Incorrect IRQ/IO addr. with Zipslack's "tulip" ethernet driver jeffg84 Linux - Networking 0 04-08-2003 01:46 PM
Red Hat 7.3 Installation-"incorrect CDROM" shootdawe Linux - Distributions 4 09-17-2002 09:49 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:37 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration