LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 04-28-2006, 03:22 AM   #1
rblampain
Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 7
Posts: 835

Rep: Reputation: 35
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 ;
$vflag+=1;
}

Should I "fix" it?

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

Rep: Reputation: 32
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, 08:49 AM   #3
Spudley
Member
 
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:
Code:
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, 12:10 PM   #4
rblampain
Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 7
Posts: 835

Original Poster
Rep: Reputation: 35
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, 04:13 PM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
$_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, 09:28 PM   #6
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 41
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:
Code:
"" == 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, 10:33 PM   #7
rblampain
Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 7
Posts: 835

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


Reply


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 09:26 AM
Get "530 Login incorrect." trying to FTP to Slackware 9.1 box. RichDawg Linux - Networking 1 07-22-2004 07:45 PM
Getting "530 Login incorrect" trying to ftp to slackware 9.1 box. RichDawg Linux - Newbie 0 07-22-2004 02:05 PM
Incorrect IRQ/IO addr. with Zipslack's "tulip" ethernet driver jeffg84 Linux - Networking 0 04-08-2003 12:46 PM
Red Hat 7.3 Installation-"incorrect CDROM" shootdawe Linux - Distributions 4 09-17-2002 08:49 AM


All times are GMT -5. The time now is 01:15 PM.

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