Re: [PHP] Switch Statement

2013-09-29 Thread Aziz Saleh
What is the output?


On Sun, Sep 29, 2013 at 1:34 AM, Ethan Rosenberg 
erosenb...@hygeiabiomedical.com wrote:

 On 09/28/2013 10:53 PM, Aziz Saleh wrote:

 Ethan, can you do a var_dump instead of print_r. It might be that
 next_step
 has spaces in it causing the switch to not match.

 Aziz


  snip

 Aziz -

 Used var_dump no further information


 Ethan


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




Re: [PHP] Switch Statement

2013-09-29 Thread mrfroasty
Hello,

I suggest you put default in that switch statement and var_dump the
$_POST.That should be enough for a programmer to pin point what goes wrong.

P:S
**You might want to consider versioning your codes to go back into its
history to see what has changed.

Muhsin

On 09/29/2013 04:33 AM, Ethan Rosenberg wrote:
 Dear List -

 I have a working program.  I made one change in a switch statement,
 and it does not work.  I'm probably missing something fundamental.

 Here are some code SNIPPETS...  [please note that all my debug
 statements are at the left margin]

 Setup...

 ?php
 session_start();
 session_name(STORE);
 set_time_limit(2400);
 ini_set('display_errors', 'on');
 ini_set('display_startup_errors', 'on');
 error_reporting(-2);

 ini_set('error_reporting', 'E_ALL | E_STRICT');
 ini_set('html_errors', 'On');
 ini_set('log_errors', 'On');
 require '/home/ethan/P/wk.inc'; //password file
 $db = Store;
 $cxn =mysqli_connect($host,$user,$password,$db);
 if (!$cxn)
 {
 die('Connect Error (' . mysqli_connect_errno() . ') '
 . mysqli_connect_error());
 }// no error   
 if($_REQUEST['welcome_already_seen']!= already_seen)   
 show_welcome();
 
 //end setup
 function show_welcome() //this is the input screen
 {
 snip

 echo  input type='hidden' name='welcome_already_seen'
 value='already_seen';
 echo  input type='hidden' name='next_step' value='step20' /;

 snip
 }

 
 //end input screen

 //Switch statement

 echo 'before';
 print_r($_POST); //post#1   

 switch ( $_POST['next_step'] )
 {

 case 'step20':
 {
 pint_r($_POST);//post#2   
 echo 'step20';
 if(!empty($_POST['Cust_Num']))
 good();
 if(empty($_POST['Cust_Num']))
 bad();
 break;
 } //end step20

 snip
 } //end switch
 
 

 post#1

 beforeArray
 (
 [Cust_Num] = 123
 [Fname] =
 [Lname] =
 [Street] =
 [City] =
 [state] = NY
 [Zip] = 10952
 [PH1] =
 [PH2] =
 [PH3] =
 [Date] =
 [welcome_already_seen] = already_seen
 [next_step] = step20

 )

 Cust_Num state and Zip are as entered.

 The switch statement is never entered, since post#2 is never
 displayed, and neither good() or bad() functions are entered.   


 TIA

 Ethan





-- 
Extra details:
OSS:Gentoo Linux
profile:x86
Hardware:msi geforce 8600GT asus p5k-se
location:/home/muhsin
language(s):C/C++,PHP
Typo:40WPM
url:http://www.mzalendo.net
url:http://www.zanbytes.com



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



Re: [PHP] Switch Statement

2013-09-28 Thread Aziz Saleh
Ethan, can you do a var_dump instead of print_r. It might be that next_step
has spaces in it causing the switch to not match.

Aziz


On Sat, Sep 28, 2013 at 10:33 PM, Ethan Rosenberg 
erosenb...@hygeiabiomedical.com wrote:

 Dear List -

 I have a working program.  I made one change in a switch statement, and it
 does not work.  I'm probably missing something fundamental.

 Here are some code SNIPPETS...  [please note that all my debug statements
 are at the left margin]

 Setup...

 ?php
 session_start();
 session_name(STORE);
 set_time_limit(2400);
 ini_set('display_errors', 'on');
 ini_set('display_startup_**errors', 'on');
 error_reporting(-2);

 ini_set('error_reporting', 'E_ALL | E_STRICT');
 ini_set('html_errors', 'On');
 ini_set('log_errors', 'On');
 require '/home/ethan/P/wk.inc'; //password file
 $db = Store;
 $cxn =mysqli_connect($host,$user,$**password,$db);
 if (!$cxn)
 {
 die('Connect Error (' . mysqli_connect_errno() . ') '
 . mysqli_connect_error());
 }// no error
 if($_REQUEST['welcome_already_**seen']!= already_seen)

 show_welcome();

 //end setup
 function show_welcome() //this is the input screen
 {
 snip

 echo  input type='hidden' name='welcome_already_seen'
 value='already_seen';
 echo  input type='hidden' name='next_step' value='step20' /;

 snip
 }


 //end input screen

 //Switch statement

 echo 'before';
 print_r($_POST); //post#1

 switch ( $_POST['next_step'] )
 {

 case 'step20':
 {
 pint_r($_POST); //post#2
 echo 'step20';
 if(!empty($_POST['Cust_Num']))
 good();
 if(empty($_POST['Cust_Num']))
 bad();
 break;
 } //end step20

 snip
 } //end switch



 post#1

 beforeArray
 (
 [Cust_Num] = 123
 [Fname] =
 [Lname] =
 [Street] =
 [City] =
 [state] = NY
 [Zip] = 10952
 [PH1] =
 [PH2] =
 [PH3] =
 [Date] =
 [welcome_already_seen] = already_seen
 [next_step] = step20

 )

 Cust_Num state and Zip are as entered.

 The switch statement is never entered, since post#2 is never displayed,
 and neither good() or bad() functions are entered.


 TIA

 Ethan



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




Re: [PHP] Switch Statement

2013-09-28 Thread Ethan Rosenberg

On 09/28/2013 10:53 PM, Aziz Saleh wrote:

Ethan, can you do a var_dump instead of print_r. It might be that next_step
has spaces in it causing the switch to not match.

Aziz



snip

Aziz -

Used var_dump no further information

Ethan


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



Re: [PHP] UNLESS Statement Equivalent

2013-03-11 Thread Jonathan Sundquist
Since you already have the return statement with the if statement the else
isn't required. If those three statements are true you would exit the call
any ways
On Mar 11, 2013 4:33 PM, Angela Barone ang...@italian-getaways.com
wrote:

 I'm looking for an 'unless' statement, but as far as I can tell,
 PHP doesn't have one.  Hopefully someone can help me rewrite my statement.

 In English, I want to say: always do something UNLESS these 3
 conditions are met.

 The best I've been able to come up with in PHP is this:

 if ( ($current_page == $saved_page) and ($current_ip == $saved_ip) and
 ($current_dt  ($saved_dt + 3600)) ) {
 return;
 } else {
 $query  = UPDATE `table` SET `hits` = '$count', `agent` =
 '$agent', `ts` = '$date_time'  WHERE `page` = '$page';
 $result = mysql_query($query) or die ('Error! -- ' .
 mysql_error());
 }

 However, I've read where this is not really acceptable.  Can
 someone help me eliminate the 'else' portion of this if statement?

 Thank you,
 Angela

 P.S.  I realize the above isn't complete code but it should still be
 clear.  If not, let me know.
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] UNLESS Statement Equivalent

2013-03-11 Thread Ashley Sheridan
On Mon, 2013-03-11 at 16:38 -0500, Jonathan Sundquist wrote:

 Since you already have the return statement with the if statement the else
 isn't required. If those three statements are true you would exit the call
 any ways
 On Mar 11, 2013 4:33 PM, Angela Barone ang...@italian-getaways.com
 wrote:
 
  I'm looking for an 'unless' statement, but as far as I can tell,
  PHP doesn't have one.  Hopefully someone can help me rewrite my statement.
 
  In English, I want to say: always do something UNLESS these 3
  conditions are met.
 
  The best I've been able to come up with in PHP is this:
 
  if ( ($current_page == $saved_page) and ($current_ip == $saved_ip) and
  ($current_dt  ($saved_dt + 3600)) ) {
  return;
  } else {
  $query  = UPDATE `table` SET `hits` = '$count', `agent` =
  '$agent', `ts` = '$date_time'  WHERE `page` = '$page';
  $result = mysql_query($query) or die ('Error! -- ' .
  mysql_error());
  }
 
  However, I've read where this is not really acceptable.  Can
  someone help me eliminate the 'else' portion of this if statement?
 
  Thank you,
  Angela
 
  P.S.  I realize the above isn't complete code but it should still be
  clear.  If not, let me know.
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 


What about this:

if ( !( ($current_page == $saved_page) and ($current_ip == $saved_ip)
and ($current_dt  ($saved_dt + 3600)) ) )

The 3 sub-expressions are grouped with an extra set of brackets and
the ! inverts the whole thing, so no need for an else clause.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] UNLESS Statement Equivalent

2013-03-11 Thread Angela Barone
On Mar 11, 2013, at 2:38 PM, Jonathan Sundquist wrote:

 Since you already have the return statement with the if statement the else 
 isn't required. If those three statements are true you would exit the call 
 any ways

I don't follow.  The else contains the meat of the statement. 

Angela

Re: [PHP] UNLESS Statement Equivalent

2013-03-11 Thread Jonathan Sundquist
What you have

if ( ($current_page == $saved_page) and ($current_ip == $saved_ip) and
($current_dt  ($saved_dt + 3600)) ) {
return;
} else {
$query  = UPDATE `table` SET `hits` = '$count', `agent` =
'$agent', `ts` = '$date_time'  WHERE `page` = '$page';
$result = mysql_query($query) or die ('Error! -- ' . mysql_error());
}

is the same as writing it as

if ( ($current_page == $saved_page)  ($current_ip == $saved_ip) 
($current_dt  ($saved_dt + 3600)) ) {
return;
}

$query  = UPDATE `table` SET `hits` = '$count', `agent` = '$agent', `ts` =
'$date_time'  WHERE `page` = '$page';
$result = mysql_query($query) or die ('Error! -- ' . mysql_error());



On Mon, Mar 11, 2013 at 5:48 PM, Angela Barone
ang...@italian-getaways.comwrote:

 On Mar 11, 2013, at 2:38 PM, Jonathan Sundquist wrote:

 Since you already have the return statement with the if statement the else
 isn't required. If those three statements are true you would exit the call
 any ways


 I don't follow.  The else contains the meat of the statement.

 Angela



Re: [PHP] UNLESS Statement Equivalent

2013-03-11 Thread Angela Barone
On Mar 11, 2013, at 3:47 PM, Ashley Sheridan wrote:
 if ( !( ($current_page == $saved_page) and ($current_ip == $saved_ip) and 
 ($current_dt  ($saved_dt + 3600)) ) )

Hello Ash,

This makes sense to me, but I can't get it to work, so I'm either not 
understanding it or I'm asking the wrong question.  Here's a complete scriptlet:

?php
$saved_page = 'ddd';
$page   = 'ddd';
$saved_ip   = '1.1.1.1';
$ip = '1.1.1.1';
$saved_dt   = '2013-03-11 11:11:11';
$current_dt = '2013-03-11 11:22:11';

if ( !( ($current_page == $saved_page) and ($current_ip == $saved_ip) and 
($current_dt  ($saved_dt + 3600)) ) ) {
echo 'Save results.';
} else {
echo Don't save.;
}
?

Using the supplied data, the result should be Don't save.  Can you 
see what's wrong?

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



Re: [PHP] UNLESS Statement Equivalent

2013-03-11 Thread Jonathan Sundquist
Angela,

the variable $current_page does not exist. so $curent_page does not equal
$saved_page.  Also the ! in front of the entire statement means that all of
this is false.  Since one items is true and not true = false Don't save
is echoed out.

If you are looking to save the results based on the above sample it would
look like


if(($page === $saved_page)  ($current_ip === $saved_ip)  ($current_dt 
($saved_dt +3600)) {
 //save the results
} else {
//don't save
}

I would also suggest keeping with your original statement to return early
and return often. Its best to exit out of your functions sooner than later.
 Specially if its a large function.


On Mon, Mar 11, 2013 at 6:03 PM, Angela Barone
ang...@italian-getaways.comwrote:

 On Mar 11, 2013, at 3:47 PM, Ashley Sheridan wrote:
  if ( !( ($current_page == $saved_page) and ($current_ip == $saved_ip)
 and ($current_dt  ($saved_dt + 3600)) ) )

 Hello Ash,

 This makes sense to me, but I can't get it to work, so I'm either
 not understanding it or I'm asking the wrong question.  Here's a complete
 scriptlet:

 ?php
 $saved_page = 'ddd';
 $page   = 'ddd';
 $saved_ip   = '1.1.1.1';
 $ip = '1.1.1.1';
 $saved_dt   = '2013-03-11 11:11:11';
 $current_dt = '2013-03-11 11:22:11';

 if ( !( ($current_page == $saved_page) and ($current_ip == $saved_ip) and
 ($current_dt  ($saved_dt + 3600)) ) ) {
 echo 'Save results.';
 } else {
 echo Don't save.;
 }
 ?

 Using the supplied data, the result should be Don't save.  Can
 you see what's wrong?

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




Re: [PHP] UNLESS Statement Equivalent

2013-03-11 Thread Angela Barone
On Mar 11, 2013, at 4:10 PM, Jonathan Sundquist wrote:
 the variable $current_page does not exist. 

That was my problem. :(  I've been staring at this for too long.  Too 
bad there's not a 'use strict' pragma.

 I would also suggest keeping with your original statement to return early and 
 return often. Its best to exit out of your functions sooner than later.  
 Specially if its a large function.

O.K.  I just thought there might be a more elegant way of doing it.  I 
at least got rid of the else statement like you mentioned.

Thanks for your help,
Angela

Re: [PHP] UNLESS Statement Equivalent

2013-03-11 Thread Larry Garfield

On 3/11/13 6:25 PM, Angela Barone wrote:

On Mar 11, 2013, at 4:10 PM, Jonathan Sundquist wrote:

the variable $current_page does not exist.


That was my problem. :(  I've been staring at this for too long.  Too 
bad there's not a 'use strict' pragma.


There is.  Always set your development environment to E_ALL | E_STRICT, 
and it will yell at you about every little thing, including undefined 
variables.


http://php.net/manual/en/function.error-reporting.php


I would also suggest keeping with your original statement to return early and 
return often. Its best to exit out of your functions sooner than later.  
Specially if its a large function.


O.K.  I just thought there might be a more elegant way of doing it.  I 
at least got rid of the else statement like you mentioned.

Thanks for your help,
Angela


If you find yourself with a function that's too long and complex from 
the if-statements, your first step is to break it up into utility functions.


if (...) {
  // Something Long
}
else {
  // Something Else Long
}

Becomes:

if (...) {
  something_long();
}
else {
  something_else_long();
}

function something_long() {

}

function something_else_long() {

}

That helps both readability and testability.

Also, on your original boolean question, note that negation is 
distributive.  That is:


!($a  $b  $c)

is the same as:

!$a || !$b || $!c

Which means that if your checks are all equality checks, as in your 
case, you can simply do:


if ($a != 'a' || $b != 'b' || $c = 'c') {

}

Which may be easier to read.  If those checks are not trivial then 
there's also a micro-performance benefit there, as the first statement 
that evaluates to true will cause the whole thing to return true, so the 
second and third options don't need to be evaluated.


--Larry Garfield

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



Re: [PHP] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread Joseph Thayne
Try putting tick marks (`) around the field and table names.  So your 
SQL query would then look like:


INSERT INTO `history` (`v_id`, `hour`, `visits`, `date`) VALUES (45, 0, 
59, '2010 01 27');


This is a good practice to get into.  The problem is that MySQL allows 
you to create tables and fields with the same name as functions.  If the 
tick marks are not there, then it assumes you mean to try using the 
function.  In your case, hour is a function in mysql.  I would assume 
that the reason it works in phpmyadmin is that it filters the query 
somehow to add the tick marks in.


Joseph

james stojan wrote:

I'm at my wits end trying to make this mysql statement insert work in
PHP. I'm not getting any errors from PHP or mysql but the insert fails
(nothing is inserted) error reporting is on and is reporting other
errors. When I echo out the query and manually paste it into PHP
myAdmin the query inserts without a problem. I know that I am
connecting to the database as well part of the data being inserted
comes from the same database and that the mysql user has permission to
do inserts (even tried as root no luck).

$query=INSERT INTO upload_history (v_id,hour,visits,date) VALUES
(.$v_id.,.$hour.,.$visits.,'$date1'.);;

$r2=mysql_query($query) or die(bA fatal MySQL error
occured/b.\nbr /Query:  . $query . br /\nError: ( .
mysql_errno() . )  . mysql_error());

This is an echo of $query and runs in phpmyadmin.

INSERT INTO history (v_id,hour,visits,date) VALUES (45,0,59,'2010 01 27');


Any idea what is going on here?

  


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



Re: [PHP] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread Kim Madsen

james stojan wrote on 11/02/2010 22:21:


$query=INSERT INTO upload_history (v_id,hour,visits,date) VALUES
(.$v_id.,.$hour.,.$visits.,'$date1'.);;


The ,'$date1'. is not correct syntax, change it to ,'.$date.'


--
Kind regards
Kim Emax - masterminds.dk

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



Re: [PHP] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread Mari Masuda
Also, in PHP you should NOT put the last semi-colon at the end of your SQL 
statement.  http://www.php.net/manual/en/function.mysql-query.php

On Feb 11, 2010, at 1:26 PM, Joseph Thayne wrote:

 Try putting tick marks (`) around the field and table names.  So your SQL 
 query would then look like:
 
 INSERT INTO `history` (`v_id`, `hour`, `visits`, `date`) VALUES (45, 0, 59, 
 '2010 01 27');
 
 This is a good practice to get into.  The problem is that MySQL allows you to 
 create tables and fields with the same name as functions.  If the tick marks 
 are not there, then it assumes you mean to try using the function.  In your 
 case, hour is a function in mysql.  I would assume that the reason it works 
 in phpmyadmin is that it filters the query somehow to add the tick marks in.
 
 Joseph
 
 james stojan wrote:
 I'm at my wits end trying to make this mysql statement insert work in
 PHP. I'm not getting any errors from PHP or mysql but the insert fails
 (nothing is inserted) error reporting is on and is reporting other
 errors. When I echo out the query and manually paste it into PHP
 myAdmin the query inserts without a problem. I know that I am
 connecting to the database as well part of the data being inserted
 comes from the same database and that the mysql user has permission to
 do inserts (even tried as root no luck).
 
 $query=INSERT INTO upload_history (v_id,hour,visits,date) VALUES
 (.$v_id.,.$hour.,.$visits.,'$date1'.);;
 
 $r2=mysql_query($query) or die(bA fatal MySQL error
 occured/b.\nbr /Query:  . $query . br /\nError: ( .
 mysql_errno() . )  . mysql_error());
 
 This is an echo of $query and runs in phpmyadmin.
 
 INSERT INTO history (v_id,hour,visits,date) VALUES (45,0,59,'2010 01 27');
 
 
 Any idea what is going on here?
 
  
 
 -- 
 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] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread james stojan
Thank you.
You were right on the money, hour was the problem and the tick marks
solved it. I spent 3 hours trying to figure out why I never got an error but
there was no insert and  php myadmin does add the tick marks automatically.
 Probably a good habit to always use the tick marks.

Learn something new everyday.

On Thu, Feb 11, 2010 at 4:26 PM, Joseph Thayne webad...@thaynefam.orgwrote:

 Try putting tick marks (`) around the field and table names.  So your SQL
 query would then look like:


 INSERT INTO `history` (`v_id`, `hour`, `visits`, `date`) VALUES (45, 0, 59,
 '2010 01 27');

 This is a good practice to get into.  The problem is that MySQL allows you
 to create tables and fields with the same name as functions.  If the tick
 marks are not there, then it assumes you mean to try using the function.  In
 your case, hour is a function in mysql.  I would assume that the reason it
 works in phpmyadmin is that it filters the query somehow to add the tick
 marks in.

 Joseph


 james stojan wrote:

 I'm at my wits end trying to make this mysql statement insert work in
 PHP. I'm not getting any errors from PHP or mysql but the insert fails
 (nothing is inserted) error reporting is on and is reporting other
 errors. When I echo out the query and manually paste it into PHP
 myAdmin the query inserts without a problem. I know that I am
 connecting to the database as well part of the data being inserted
 comes from the same database and that the mysql user has permission to
 do inserts (even tried as root no luck).

 $query=INSERT INTO upload_history (v_id,hour,visits,date) VALUES
 (.$v_id.,.$hour.,.$visits.,'$date1'.);;

 $r2=mysql_query($query) or die(bA fatal MySQL error
 occured/b.\nbr /Query:  . $query . br /\nError: ( .
 mysql_errno() . )  . mysql_error());

 This is an echo of $query and runs in phpmyadmin.

 INSERT INTO history (v_id,hour,visits,date) VALUES (45,0,59,'2010 01 27');


 Any idea what is going on here?






Re: [PHP] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread Joseph Thayne


Actually, the syntax is just fine.  I personally would prefer it the way 
you mention, but there actually is nothing wrong with the syntax.



The ,'$date1'. is not correct syntax, change it to ,'.$date.'


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



Re: [PHP] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread James McLean
On Fri, Feb 12, 2010 at 8:27 AM, Joseph Thayne webad...@thaynefam.org wrote:

 Actually, the syntax is just fine.  I personally would prefer it the way you
 mention, but there actually is nothing wrong with the syntax.

 The ,'$date1'. is not correct syntax, change it to ,'.$date.'

My personal preference these days is to use Curly braces around
variables in strings such as this, I always find excessive string
concatenation such as is often used when building SQL queries hard to
read, and IIRC there was performance implications to it as well
(though I don't have access to concrete stats right now).

In your case, the variable would be something like this:

$query=INSERT INTO upload_history (v_id,hour,visits,date) VALUES
({$v_id}, {$hour}, {$visits}, '{$date}');

Much more readable and maintainable IMO.

No need for the trailing semicolon in SQL that uses an API like you
are using so save another char there too.
Backticks around column names are not required and IMO again they just
make the code hard to read. Just because phpMyAdmin uses them, doesn't
mean we all need to.

Cheers

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



Re: [PHP] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread Joseph Thayne
That is a good idea to use the curly braces.  I consistently forget 
about them, and fell like an idiot every time I am reminded of them.


As for the backticks, they are required because of MySQL, not because of 
phpMyAdmin.  The issue was not that phpMyAdmin uses backticks, it is 
that MySQL pretty much requires them when naming a field the same as an 
internal function to my knowledge.  If someone else knows of another way 
to designate to MySQL that a field named HOUR is the name of a field 
rather than the name of the internal function, I would love to know.


James McLean wrote:

On Fri, Feb 12, 2010 at 8:27 AM, Joseph Thayne webad...@thaynefam.org wrote:
  

Actually, the syntax is just fine.  I personally would prefer it the way you
mention, but there actually is nothing wrong with the syntax.



The ,'$date1'. is not correct syntax, change it to ,'.$date.'
  


My personal preference these days is to use Curly braces around
variables in strings such as this, I always find excessive string
concatenation such as is often used when building SQL queries hard to
read, and IIRC there was performance implications to it as well
(though I don't have access to concrete stats right now).

In your case, the variable would be something like this:

$query=INSERT INTO upload_history (v_id,hour,visits,date) VALUES
({$v_id}, {$hour}, {$visits}, '{$date}');

Much more readable and maintainable IMO.

No need for the trailing semicolon in SQL that uses an API like you
are using so save another char there too.
Backticks around column names are not required and IMO again they just
make the code hard to read. Just because phpMyAdmin uses them, doesn't
mean we all need to.

Cheers

  


Re: [PHP] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread Jochem Maas
Op 2/11/10 10:51 PM, James McLean schreef:
 On Fri, Feb 12, 2010 at 8:27 AM, Joseph Thayne webad...@thaynefam.org wrote:

 Actually, the syntax is just fine.  I personally would prefer it the way you
 mention, but there actually is nothing wrong with the syntax.

 The ,'$date1'. is not correct syntax, change it to ,'.$date.'
 
 My personal preference these days is to use Curly braces around
 variables in strings such as this, I always find excessive string
 concatenation such as is often used when building SQL queries hard to
 read, and IIRC there was performance implications to it as well
 (though I don't have access to concrete stats right now).
 
 In your case, the variable would be something like this:
 
 $query=INSERT INTO upload_history (v_id,hour,visits,date) VALUES
 ({$v_id}, {$hour}, {$visits}, '{$date}');

actually IIRC the engine compiles that to OpCodes that equate to:


$query = 'INSERT INTO upload_history (v_id,hour,visits,date) VALUES ('.$v_id.', 
'.$hour.', '.$visits.', '\''.{$date}.'\')';

 
 Much more readable and maintainable IMO.
 
 No need for the trailing semicolon in SQL that uses an API like you
 are using so save another char there too.
 Backticks around column names are not required and IMO again they just
 make the code hard to read. Just because phpMyAdmin uses them, doesn't
 mean we all need to.
 
 Cheers
 


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



Re: [PHP] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread James McLean
On Fri, Feb 12, 2010 at 9:31 AM, Jochem Maas joc...@iamjochem.com wrote:
 Op 2/11/10 10:51 PM, James McLean schreef:
 My personal preference these days is to use Curly braces around
 variables in strings such as this, I always find excessive string
 concatenation such as is often used when building SQL queries hard to
 read, and IIRC there was performance implications to it as well
 (though I don't have access to concrete stats right now).

 In your case, the variable would be something like this:

 $query=INSERT INTO upload_history (v_id,hour,visits,date) VALUES
 ({$v_id}, {$hour}, {$visits}, '{$date}');

 actually IIRC the engine compiles that to OpCodes that equate to:

 $query = 'INSERT INTO upload_history (v_id,hour,visits,date) VALUES 
 ('.$v_id.', '.$hour.', '.$visits.', '\''.{$date}.'\')';

Interesting point, but the original code is still more readable, the
opcode's aren't our problem (at least in this case) :)

Cheers

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



Re: [PHP] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread James McLean
On Fri, Feb 12, 2010 at 9:31 AM, Joseph Thayne webad...@thaynefam.org wrote:
 As for the backticks, they are required because of MySQL, not because of
 phpMyAdmin.  The issue was not that phpMyAdmin uses backticks, it is that
 MySQL pretty much requires them when naming a field the same as an internal
 function to my knowledge.  If someone else knows of another way to designate
 to MySQL that a field named HOUR is the name of a field rather than the name
 of the internal function, I would love to know.

Ahh I see :) Wasn't aware of that. Personally i've always been
over-descriptive when designing my tables which is possibly why I've
never run into that limitation :)

Thanks.

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



Re: [PHP] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread Joseph Thayne
Yeah, I am a lot more descriptive now.  I ran into it quite a bit when I 
was first starting out.


James McLean wrote:

On Fri, Feb 12, 2010 at 9:31 AM, Joseph Thayne webad...@thaynefam.org wrote:
  

As for the backticks, they are required because of MySQL, not because of
phpMyAdmin.  The issue was not that phpMyAdmin uses backticks, it is that
MySQL pretty much requires them when naming a field the same as an internal
function to my knowledge.  If someone else knows of another way to designate
to MySQL that a field named HOUR is the name of a field rather than the name
of the internal function, I would love to know.



Ahh I see :) Wasn't aware of that. Personally i've always been
over-descriptive when designing my tables which is possibly why I've
never run into that limitation :)

Thanks.

  


Re: [PHP] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread Paul M Foster
On Fri, Feb 12, 2010 at 09:44:47AM +1030, James McLean wrote:

 On Fri, Feb 12, 2010 at 9:31 AM, Joseph Thayne webad...@thaynefam.org wrote:
  As for the backticks, they are required because of MySQL, not because of
  phpMyAdmin.  The issue was not that phpMyAdmin uses backticks, it is that
  MySQL pretty much requires them when naming a field the same as an internal
  function to my knowledge.  If someone else knows of another way to designate
  to MySQL that a field named HOUR is the name of a field rather than the name
  of the internal function, I would love to know.

Backticks are also required to preserve casing in MySQL, if you name
something in mixed or upper case; MySQL lowercases table and field names
otherwise. It's a silly misfeature of MySQL. 

I can't conceive of why a DBMS would assume something which should be
understood in the context of a field name should instead be interpreted
as a function call. Buy maybe that's just me.

Paul

-- 
Paul M. Foster

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



RE: [PHP] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread Joseph Thayne
I was going to write an example as to what should happen instead of what
actually does when id dawned on me why MySQL works the way it does.  One of
the biggest complaints people have with MySQL is in speed.  To demonstrate
what I just realized, take the following statement that will select the hour
from a given time as well as the value from the hour field:

SELECT HOUR('13:42:37') as thehour, hour FROM mytable;

Not a big deal and pretty straight forward.  What about the following?

SELECT HOUR(mydate) as thehour, hour FROM mytable;

Still pretty simple to determine which are the functions and which are the
field names.  However, take the following:

SELECT HOUR(NOW()) as thehour, hour FROM mytable;

As humans, glancing at it, it makes perfect sense to us as to which is
which.  However, try telling a computer how to interpret the above
statement.  You could look for parenthesis.  That would work fine on the
first two statements, but once you get to the third, you have to worry about
recursion and all possible permutations of the data that could come through.
This exponentially increases the complexity and processing time/power
required to run the query.  Granted, that query is a simple one, but plug it
into a query filled with multiple joins, and you have the potential of a
nightmare.  So why focus on adding in functionality that adds so much
complexity and will end up requiring that much extra support when a simple
character (the tick mark) will take care of the work for you and you can
then focus on other things such as data integrity and general processing
speed?

Joseph

-Original Message-
From: Paul M Foster [mailto:pa...@quillandmouse.com] 
Sent: Thursday, February 11, 2010 9:15 PM
To: php-general@lists.php.net
Subject: Re: [PHP] Mysql statement works in phpmyadmin but not in php page

On Fri, Feb 12, 2010 at 09:44:47AM +1030, James McLean wrote:

 On Fri, Feb 12, 2010 at 9:31 AM, Joseph Thayne webad...@thaynefam.org
wrote:
  As for the backticks, they are required because of MySQL, not because of
  phpMyAdmin.  The issue was not that phpMyAdmin uses backticks, it is
that
  MySQL pretty much requires them when naming a field the same as an
internal
  function to my knowledge.  If someone else knows of another way to
designate
  to MySQL that a field named HOUR is the name of a field rather than the
name
  of the internal function, I would love to know.

Backticks are also required to preserve casing in MySQL, if you name
something in mixed or upper case; MySQL lowercases table and field names
otherwise. It's a silly misfeature of MySQL. 

I can't conceive of why a DBMS would assume something which should be
understood in the context of a field name should instead be interpreted
as a function call. Buy maybe that's just me.

Paul

-- 
Paul M. Foster

-- 
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] Mysql statement works in phpmyadmin but not in php page

2010-02-11 Thread Paul M Foster
On Thu, Feb 11, 2010 at 09:49:02PM -0600, Joseph Thayne wrote:

 I was going to write an example as to what should happen instead of what
 actually does when id dawned on me why MySQL works the way it does.  One of
 the biggest complaints people have with MySQL is in speed.  

The much-vaunted speed of MySQL is the biggest complaint? Sheesh.

 To demonstrate
 what I just realized, take the following statement that will select the hour
 from a given time as well as the value from the hour field:
 
 SELECT HOUR('13:42:37') as thehour, hour FROM mytable;
 
 Not a big deal and pretty straight forward.  What about the following?
 
 SELECT HOUR(mydate) as thehour, hour FROM mytable;
 
 Still pretty simple to determine which are the functions and which are the
 field names.  However, take the following:
 
 SELECT HOUR(NOW()) as thehour, hour FROM mytable;
 
 As humans, glancing at it, it makes perfect sense to us as to which is
 which.  However, try telling a computer how to interpret the above
 statement.  You could look for parenthesis.  That would work fine on the
 first two statements, but once you get to the third, you have to worry about
 recursion and all possible permutations of the data that could come through.
 This exponentially increases the complexity and processing time/power
 required to run the query.  Granted, that query is a simple one, but plug it
 into a query filled with multiple joins, and you have the potential of a
 nightmare.  So why focus on adding in functionality that adds so much
 complexity and will end up requiring that much extra support when a simple
 character (the tick mark) will take care of the work for you and you can
 then focus on other things such as data integrity and general processing
 speed?

I understand what you're saying, and you may be right about why MySQL
was built this way. However, it's like telling the programmers not to
build a better parser; just make the user backtick stuff so we don't
have to write a proper parser. For a one-off script only I was going to
use, I'd do this. But not for a professional level product used by
millions, speed or no speed. Imagine if KR had tried to shortcut the C
parser this way; the C parser is almost endlessly re-entrant and must
accommodate some seriously obfuscated code. Which it does reliably.
Besides, if you've got a parser which understands joins, parsing things
like the distinction between hour (field name) and hour (function call)
is a piece of cake.

If a programmer working for me tried to pawn this off as a done, I'd
make him redo it. Again, maybe it's just me.

Anyway, we're way off topic

Paul

-- 
Paul M. Foster

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



Re: [PHP] Switch statement Question

2009-01-30 Thread Thodoris


Hi, 
 
  I have a code snippet here as in the following:
 
//Switch statements between the four options 
switch($string) {

case :
$string= NOT book.author='All';
break;
default:
$string= $string . AND NOT book.author='All';
break;
}
  This code does work, but I am wondering if it is possible in the switch statement clauses for me to do something like case does not equal to a certain author name if I don't want $string with that content to be processed. or, do I always use default in this case? 
 
Thanks in advance. 
 
Alice  
_

All-in-one security and maintenance for your PC.  Get a free 90-day trial!
http://www.windowsonecare.com/purchase/trial.aspx?sc_cid=wl_wlmail
  


Well I will have to mention that switch becomes if after all internally 
so you could always use the if statement.


I am a great fan of switch but since eclipse fail to format correctly 
embedded switch statements I am starting to use the old all good if() 
since it is the same thing. It is a matter of style actually although 
switch is slightly slower (so slightly that you can't notice in any case).


I think there was a thread in this list for this comparison a few days ago.

--
Thodoris


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



RE: [PHP] Switch statement Question

2009-01-29 Thread Boyd, Todd M.
 -Original Message-
 From: Alice Wei [mailto:aj...@alumni.iu.edu]
 Sent: Thursday, January 29, 2009 3:02 PM
 To: php-general@lists.php.net
 Subject: [PHP] Switch statement Question
 
 
 Hi,
 
   I have a code snippet here as in the following:
 
 //Switch statements between the four options
 switch($string) {
 case :
 $string= NOT book.author='All';
 break;
 default:
 $string= $string . AND NOT book.author='All';
 break;
 }
   This code does work, but I am wondering if it is possible in the
 switch statement clauses for me to do something like case does not
 equal to a certain author name if I don't want $string with that
 content to be processed. or, do I always use default in this case?

It's a bit non-conventional, but the switch block can be used like so:

switch(true) {
case (x  y):
dosomething();
break;
case (y == 0):
dosomethingelse();
break;
default:
somethingelseentirely();
break;
}

...this way, your case statements can be expressions themselves, and it
will always pick at least one of them to fire.

HTH,


// Todd

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



Re: [PHP] Switch statement Question

2009-01-29 Thread Jochem Maas
Boyd, Todd M. schreef:
 -Original Message-
 From: Alice Wei [mailto:aj...@alumni.iu.edu]
 Sent: Thursday, January 29, 2009 3:02 PM
 To: php-general@lists.php.net
 Subject: [PHP] Switch statement Question


 Hi,

   I have a code snippet here as in the following:

 //Switch statements between the four options
 switch($string) {
 case :
 $string= NOT book.author='All';
 break;
 default:
 $string= $string . AND NOT book.author='All';
 break;
 }
   This code does work, but I am wondering if it is possible in the
 switch statement clauses for me to do something like case does not
 equal to a certain author name if I don't want $string with that
 content to be processed. or, do I always use default in this case?
 
 It's a bit non-conventional, but the switch block can be used like so:
 
 switch(true) {
   case (x  y):
   dosomething();
   break;
   case (y == 0):
   dosomethingelse();
   break;
   default:
   somethingelseentirely();
   break;
 }

some people really don't like this kind of thing (hi Robbert :-)),
either way beware that the equality test is not strict, that is
to say autocasting occurs (variable type doesn't have to match)

an example:

switch (true) {
case 1:
echo did you expect this?\n; // -- this is output
break;
case true:
echo or this?\n;
break;
}



 ...this way, your case statements can be expressions themselves, and it
 will always pick at least one of them to fire.
 
 HTH,
 
 
 // Todd
 


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



Re: [PHP] prepared statement

2008-06-26 Thread ctx2002

thanks for answering my question.

I have checked PHP PDO doc. 
PDO:: query() can send a query to server.
my question is, does PDO:: query() generates prepared statement
automatically?
or I have to explicitly call PDO:: prepare() to use prepared statement?

for example:

PDO:: query(select name from contact where id = 1) will send a raw SQL
statement 
to server, and server also treat that query as a raw SQL statement.

regards
-- 
View this message in context: 
http://www.nabble.com/prepared-statement-tp18123270p18142905.html
Sent from the PHP - General mailing list archive at Nabble.com.


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



Re: [PHP] prepared statement

2008-06-26 Thread Chris
ctx2002 wrote:
 thanks for answering my question.
 
 I have checked PHP PDO doc. 
 PDO:: query() can send a query to server.
 my question is, does PDO:: query() generates prepared statement
 automatically?
 or I have to explicitly call PDO:: prepare() to use prepared statement?

You have to use prepare/execute to get prepared statements.

Query does a straight query (same as mysql_query or pg_query or whatever
else you're using).

-- 
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] prepared statement

2008-06-25 Thread Chris
ctx2002 wrote:
 Hi all:
 
 We are use PHP PDO's Prepared statement to send SQL query to Mysql server.
 According to PHP PDO doc, Prepared statement are fast for executing multiple
 SQL queries with same parameters. by using prepared statement you avoid
 repeating the analyze/compile/optimize cycle
 
 Our application is a web application, each request will have a new Prepared
 statement handler generated by PDO Lib. so prepared statement actually
 slower than non-prepared statement.
 
 I just want to know how can we cache  Prepared statement handler, So we can
 re use it in later http request.
 
 for example:
 
 we have a query to pull out all product information from mysql db, each
 query just has a different product id , all other parts are same. 

The query is the same.

It works out to be:

select * from products where id='X';


So you can just do something like this:

$product_query = $dbh-prepare('SELECT * from products where id=?');

$ids = array(1,2,3,4,5);

foreach ($ids as $product_id) {
  $product_query-execute(array($product_id));
  $product_details = $product_query-FetchAll();
  print_r($product_details);
}

-- 
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] prepared statement

2008-06-25 Thread ctx2002


I mean for each different requests/connection how can i use same prepared
statements object that was 
generated by PDO lib/mysql Server.

is Mysql server cache prepared statement plan?

for example:

client one connect to our site, and send a prepared statement  to our mysql
DB, now the DB will compile that prepared statement and save it somewhere in
Server. now client two connect to our site and send same prepared statement
except has a different ID to our DB, does PHP pdo / mysql server will re use
that compiled prepared statement or the php PDO/mysql server will  re
compile prepared statement for client 2? 

regards
-- 
View this message in context: 
http://www.nabble.com/prepared-statement-tp18123270p18124675.html
Sent from the PHP - General mailing list archive at Nabble.com.


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



Re: [PHP] prepared statement

2008-06-25 Thread Chris
ctx2002 wrote:
 
 I mean for each different requests/connection how can i use same prepared
 statements object that was 
 generated by PDO lib/mysql Server.

You can't.

Resources/connections are done per request and can't be shared - it's
done that way by design.

-- 
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] prepared statement

2008-06-25 Thread ctx2002

so only benefit for use prepared statement in Web environment is to prevent
SQL 
injection?

regards
 

chris smith-9 wrote:
 
 ctx2002 wrote:
 
 I mean for each different requests/connection how can i use same prepared
 statements object that was 
 generated by PDO lib/mysql Server.
 
 You can't.
 
 Resources/connections are done per request and can't be shared - it's
 done that way by design.
 
 -- 
 Postgresql  php tutorials
 http://www.designmagick.com/
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 

-- 
View this message in context: 
http://www.nabble.com/prepared-statement-tp18123270p18124946.html
Sent from the PHP - General mailing list archive at Nabble.com.


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



Re: [PHP] prepared statement

2008-06-25 Thread Larry Garfield
On Wednesday 25 June 2008 8:24:06 pm ctx2002 wrote:
 so only benefit for use prepared statement in Web environment is to prevent
 SQL
 injection?

 regards

It's somewhat more complicated than that.  (The following is based on my own 
experiences with PDO and a conversation with PDO's original author, Wez 
Furlong.)

A normal query is taken as a single string, parsed, executed, and returned.  
End of story.  A prepared statement is taken as a template string, parsed, 
and cached.  It then has variables passed into it, almost like a function 
call.

Caching the query once tends to cost a little bit more than just executing it 
straight.  The savings come in later calls, when you skip the compilation 
step.  You save per repeated query the amount of the compilation.

As Chris said, you can't save compiled queries between requests.  However, 
they can still be a performance benefit in certain circumstances.  With MySQL 
in particular, those circumstances are weird.

First of all, MySQL's query compiler is actually pretty damned fast to start 
with, especially with the fairly simple queries that tend to predominate in 
web applications.  So if you save the cost of a repeated compilation but the 
compilation itself is already cheap, you won't really notice much 
improvement.  Databases with slower compile engines (eg, Oracle) or queries 
that are considerably more complex (lots of joins that the compiler has to 
figure out how to optimally order, for instance) will see more of a benefit.  
You'll also, of course, see more benefit on queries that are run many many 
many times, but for anything but insert queries if you're smart you're 
already designing your app to avoid repeating the same query anyway. :-)

Secondly, MySQL's native prepared statement support is somewhat braindead, as 
it bypasses the query cache entirely.  So you can have prepared statements or 
the query cache, but not both.  For that reason, you may get better 
performance by using PDO's emulated prepared statements instead.  (Check the 
manual for how to enable that.)  That way PDO will do the prepared statement 
work and MySQL will still use the query cache.  Experiment to see if this 
helps in your case.

Also remember that PDO itself adds some overhead with its database 
abstraction.  It's far less than doing the same abstraction in userspace, but 
it is there.  A straight PDO-based query will not be as fast as, say, the 
same query run directly through ext/mysqli.  However, PDO does give you all 
of the nice things PDO gives you. :-)  

In my testing while working to port Drupal from ext/mysql[i] to PDO, I have 
found that by removing all of our userspace prepared statement code and using 
PDO instead, we're getting about a wash on performance.  We're OK with that, 
however, due to the increased security and flexibility that PDO offers.

So the answer is that PDO is not going to get you a big performance boost on 
MySQL in a typical web app, but you can probably break even on performance 
overall while adding flexibility, additional features, and a nice API.

-- 
Larry Garfield
[EMAIL PROTECTED]

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



Re: [PHP] IF statement

2007-10-19 Thread Simon
I'd suggest a tutorial or something on BOOLEAN or LOGICAL OPERATORS.

For example:
true and false = false
true or false = true
not true and not false = false
not true or not false = true
and so on...

The IF statement will simply take the result of a logical operation,
and the result will either be true or false.  The magic with IF is in
the logic that you write.

Simon

On 10/18/07, ron.php [EMAIL PROTECTED] wrote:
 I just tried to send this to the list.  I am not trying make it post again, I
 don't think I had the e-mail address correct the first time.

 I am trying to stop $component_reference from doing the echo below when the
 value is 5 or 19.  I don't have the syntax right though.  What did I miss?

 Ron

 if ( ($component_reference != 5) OR ($component_reference != 19) ) {
 echo lia href=\index.php?request= . $request . \ .
 $component_name . /a;
 }

 --
 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] IF statement

2007-10-18 Thread Robert Cummings
On Thu, 2007-10-18 at 19:57 -0500, ron.php wrote:
 I just tried to send this to the list.  I am not trying make it post again, I 
 don't think I had the e-mail address correct the first time.
 
 I am trying to stop $component_reference from doing the echo below when the 
 value is 5 or 19.  I don't have the syntax right though.  What did I miss?
 
 Ron
 
 if ( ($component_reference != 5) OR ($component_reference != 19) ) {
 echo lia href=\index.php?request= . $request . \ . 
 $component_name . /a;
 }

Use AND instead of OR. Otherwise use the following:

if( !($component_reference == 5 OR $component_reference == 19) )
{
echo lia href=\index.php?request= . $request . \ . 
$component_name . /a;
}

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



Re: [PHP] IF statement

2007-10-18 Thread Carlos Martínez González
just change OR by AND.


2007/10/19, ron.php [EMAIL PROTECTED]:
 I just tried to send this to the list.  I am not trying make it post again, I
 don't think I had the e-mail address correct the first time.

 I am trying to stop $component_reference from doing the echo below when the
 value is 5 or 19.  I don't have the syntax right though.  What did I miss?

 Ron

 if ( ($component_reference != 5) OR ($component_reference != 19) ) {
 echo lia href=\index.php?request= . $request . \ .
 $component_name . /a;
 }

 --
 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] If statement duplicating mysql records?

2007-06-21 Thread Roberto Mansfield
Jason Pruim wrote:
 
 
 The code I had worked out, originally was something along the lines of:
 
 if($row[5] ==Level1) (
 echo TRTD bgcolor=.$Level1.$row[0] /td;
 echo td bgcolor=.$Level1.$row[1]  /td;
 echo td bgcolor=.$Level1.A href='$row[2]'Instructions/A/td;
 echo TD bgcolor=.$Level1.A
 href='update.php?taskid=$row[0]'Click here!/A;
 }
 
 if($row[5] ==Level2){
 echo TRTD bgcolor=.$Level2.$row[0] /td;
 echo td bgcolor=.$Level2.$row[1]  /td;
 echo td bgcolor=.$Level2.A href='$row[2]'Instructions/A/td;
 echo TD bgcolor=.$Level2.A
 href='update.php?taskid=$row[0]'Click here!/A;
 
 {
 else
 {
 echo TRTD bgcolor=.$unclassified.$row[0] /td;
 echo td bgcolor=.$unclassified.$row[1]  /td;
 echo td bgcolor=.$unclassified.A
 href='$row[2]'Instructions/A/td;
 echo TD bgcolor=.$unclassified.A
 href='update.php?taskid=$row[0]'Click here!/A;
 
 }
 
 and what would happen is if $row[5] ==Level1 it would change the color
 to yellow, but then it would also display another line of the same info
 that would have the $unclassified color assigned to it.

Ahh, this is different from your original post. You have TWO if
statements here. So when $row[5] = Level1, it was satisfying the first
IF statement and then falling into the ELSE of the second IF statement.

Makes sense to me now why it was failing.

Roberto

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



Re: [PHP] If statement duplicating mysql records?

2007-06-21 Thread Jason Pruim


On Jun 21, 2007, at 1:42 PM, Roberto Mansfield wrote:


Jason Pruim wrote:



The code I had worked out, originally was something along the  
lines of:


if($row[5] ==Level1) (
echo TRTD bgcolor=.$Level1.$row[0] /td;
echo td bgcolor=.$Level1.$row[1]  /td;
echo td bgcolor=.$Level1.A href='$row[2]'Instructions/ 
A/td;

echo TD bgcolor=.$Level1.A
href='update.php?taskid=$row[0]'Click here!/A;
}

if($row[5] ==Level2){
echo TRTD bgcolor=.$Level2.$row[0] /td;
echo td bgcolor=.$Level2.$row[1]  /td;
echo td bgcolor=.$Level2.A href='$row[2]'Instructions/ 
A/td;

echo TD bgcolor=.$Level2.A
href='update.php?taskid=$row[0]'Click here!/A;

{
else
{
echo TRTD bgcolor=.$unclassified.$row[0] /td;
echo td bgcolor=.$unclassified.$row[1]  /td;
echo td bgcolor=.$unclassified.A
href='$row[2]'Instructions/A/td;
echo TD bgcolor=.$unclassified.A
href='update.php?taskid=$row[0]'Click here!/A;

}

and what would happen is if $row[5] ==Level1 it would change the  
color
to yellow, but then it would also display another line of the same  
info

that would have the $unclassified color assigned to it.


Ahh, this is different from your original post. You have TWO if
statements here. So when $row[5] = Level1, it was satisfying the  
first
IF statement and then falling into the ELSE of the second IF  
statement.


Makes sense to me now why it was failing.

Roberto'


It's not quite making sense to me though... My understanding of IF  
statements is if the condition is met it ignores all the other if's.  
Is that not correct? At this point it's just me trying to figure  
things out for my knowledge :)





--
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] If statement duplicating mysql records?

2007-06-21 Thread Roberto Mansfield
Jason Pruim wrote:
 
 It's not quite making sense to me though... My understanding of IF
 statements is if the condition is met it ignores all the other if's. Is
 that not correct? At this point it's just me trying to figure things out
 for my knowledge :)

No, that's not how it works. If the condition is met, the contents of
the if block are executed. If not, and there is an ELSE block, those
commands are executed. Then, the script continues after the whole
if/then/else structure.

Maybe you are thinking of an IF/ELSEIF/ELSEIF/.../ELSE structure?

if ( $row[5] == Level1 ) {
  // your commands

} elseif ( $row[5] == Level2 ) {
  // your commands

} else {
  // your commands

}

This would work in the way you are thinking. Hope this helps your
understanding.


-- 
Roberto Mansfield
Institutional Research and Application Development (IRAD)
SAS Computing

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



Re: [PHP] If statement duplicating mysql records?

2007-06-21 Thread Jason Pruim


On Jun 21, 2007, at 1:58 PM, Roberto Mansfield wrote:


Jason Pruim wrote:


It's not quite making sense to me though... My understanding of IF
statements is if the condition is met it ignores all the other  
if's. Is
that not correct? At this point it's just me trying to figure  
things out

for my knowledge :)


No, that's not how it works. If the condition is met, the contents of
the if block are executed. If not, and there is an ELSE block, those
commands are executed. Then, the script continues after the whole
if/then/else structure.

Maybe you are thinking of an IF/ELSEIF/ELSEIF/.../ELSE structure?

if ( $row[5] == Level1 ) {
  // your commands

} elseif ( $row[5] == Level2 ) {
  // your commands

} else {
  // your commands

}

This would work in the way you are thinking. Hope this helps your
understanding.



Hi Roberto,

Thanks for pointing that out, I think it looks better then having a  
bunch of related if statements with an else at the end anyway. :)


Always helps when you use the right tools for the job! :)



--
Roberto Mansfield
Institutional Research and Application Development (IRAD)
SAS Computing



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



Re: [PHP] If statement duplicating mysql records?

2007-06-21 Thread Jim Lucas

Jason Pruim wrote:


On Jun 21, 2007, at 1:58 PM, Roberto Mansfield wrote:


Jason Pruim wrote:


It's not quite making sense to me though... My understanding of IF
statements is if the condition is met it ignores all the other if's. Is
that not correct? At this point it's just me trying to figure things out
for my knowledge :)


No, that's not how it works. If the condition is met, the contents of
the if block are executed. If not, and there is an ELSE block, those
commands are executed. Then, the script continues after the whole
if/then/else structure.

Maybe you are thinking of an IF/ELSEIF/ELSEIF/.../ELSE structure?

if ( $row[5] == Level1 ) {
  // your commands

} elseif ( $row[5] == Level2 ) {
  // your commands

} else {
  // your commands

}

This would work in the way you are thinking. Hope this helps your
understanding.



Hi Roberto,

Thanks for pointing that out, I think it looks better then having a 
bunch of related if statements with an else at the end anyway. :)


Always helps when you use the right tools for the job! :)


well, the right tool for the job is a matter of choice.

Maybe I want to use a switch statement instead.

switch($row[5]) {

case 'Level1':
// Your code
break;

case 'Level2':
// Your code
break;

default:
// if none of the case statements above match, then this will be used
break;

}

Just another way to complete the same task





--Roberto Mansfield
Institutional Research and Application Development (IRAD)
SAS Computing



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




--
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare

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



Re: [PHP] If statement duplicating mysql records?

2007-06-20 Thread Jason Pruim


On Jun 19, 2007, at 4:20 PM, Jim Lucas wrote:


Jason Pruim wrote:
Okay, so I have a question... Probably pretty easy, but why would  
my if statement show more records then what are in the database?

if($row[5] =='Level4'){ // White Highlight
echo TRTD bgcolor=.$Level4.$row[0] /td;
echo td bgcolor=.$Level4.$row[1]  /td;
echo td bgcolor=.$Level4.A href ='$row 
[2]'Instructions/A/td;
echo TD bgcolor=.$Level4.A href='update.php? 
taskid=$row[0]'Click here!/A;

}// End of Level 4
 else
   {// Green Highlight
echo TRTD bgcolor=.$unclassified.$row[0] /td;
echo td bgcolor=.$unclassified.$row[1]  /td;
echo td bgcolor=.$unclassified.A href ='$row 
[2]'Instructions/A/td;
echo TD bgcolor=.$unclassified.A  
href='update.php?taskid=$row[0]'Click here!/A;

   }// End of Unclassified


Why not do it this way instead.

while( $row = mysql_fetch_array($results) ) {

$rowColor = $unclassified;

// White Highlight
if($row[5] =='Level4'){
$rowColor = $Level4;
}

echo TRTD bgcolor=.$rowColor.$row[0] /td;
echo td bgcolor=.$rowColor.$row[1]  /td;
	echo td bgcolor=.$rowColor.A href='$row[2]'Instructions/ 
A/td;
	echo TD bgcolor=.$rowColor.A href='update.php?taskid=$row 
[0]'Click here!/A;


}


And that just goes to show how much I have yet to learn! Once I typed  
that out I went from like, 86 lines of code down to 55... And it  
works as well!


Just for my own knowledge, Do you know why the else was being applied  
after the condition was met?


Thanks Jim!

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



Re: [PHP] If statement duplicating mysql records?

2007-06-20 Thread Jim Lucas

Jason Pruim wrote:


On Jun 19, 2007, at 4:20 PM, Jim Lucas wrote:


Jason Pruim wrote:
Okay, so I have a question... Probably pretty easy, but why would my 
if statement show more records then what are in the database?

if($row[5] =='Level4'){ // White Highlight
echo TRTD bgcolor=.$Level4.$row[0] /td;
echo td bgcolor=.$Level4.$row[1]  /td;
echo td bgcolor=.$Level4.A href 
='$row[2]'Instructions/A/td;
echo TD bgcolor=.$Level4.A 
href='update.php?taskid=$row[0]'Click here!/A;

}// End of Level 4
 else
   {// Green Highlight
echo TRTD bgcolor=.$unclassified.$row[0] /td;
echo td bgcolor=.$unclassified.$row[1]  /td;
echo td bgcolor=.$unclassified.A href 
='$row[2]'Instructions/A/td;
echo TD bgcolor=.$unclassified.A 
href='update.php?taskid=$row[0]'Click here!/A;

   }// End of Unclassified


Why not do it this way instead.

while( $row = mysql_fetch_array($results) ) {

$rowColor = $unclassified;

// White Highlight
if($row[5] =='Level4'){
$rowColor = $Level4;
}

echo TRTD bgcolor=.$rowColor.$row[0] /td;
echo td bgcolor=.$rowColor.$row[1]  /td;
echo td bgcolor=.$rowColor.A 
href='$row[2]'Instructions/A/td;
echo TD bgcolor=.$rowColor.A 
href='update.php?taskid=$row[0]'Click here!/A;


}


And that just goes to show how much I have yet to learn! Once I typed 
that out I went from like, 86 lines of code down to 55... And it works 
as well!


Just for my own knowledge, Do you know why the else was being applied 
after the condition was met?


Thanks Jim!




nope, couldn't guess why.

I would look at your result set and see if you had multiple lines 
returned.  One person mentioned that you might be using a JOIN in you 
SQL call.  This could lead to multiple lines.


Start investigating your SQL statement I would suggest.

--
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Unknown

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



Re: [PHP] If statement duplicating mysql records?

2007-06-20 Thread Daniel Brown

On 6/20/07, Jim Lucas [EMAIL PROTECTED] wrote:

I would look at your result set and see if you had multiple lines
returned.  One person mentioned that you might be using a JOIN in you
SQL call.  This could lead to multiple lines.

Start investigating your SQL statement I would suggest.


   Actually, it looks like this is the system I started writing out
for him a week or two ago, and unless he changed the SQL queries,
there were no JOINs in there.

   Jason, just to be sure, can you include the SQL query being sent,
first with the PHP variables (if any), then with the actual translated
SQL?

   For example:

   $sql = SELECT task_id FROM tasks WHERE
task_id='.$_POST['taskid'].' LIMIT 0,30;;

   SELECT task_id FROM tasks WHERE task_id='24' LIMIT 0,30;

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

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



Re: [PHP] If statement duplicating mysql records?

2007-06-20 Thread Jason Pruim


On Jun 20, 2007, at 10:56 AM, Daniel Brown wrote:


On 6/20/07, Jim Lucas [EMAIL PROTECTED] wrote:

I would look at your result set and see if you had multiple lines
returned.  One person mentioned that you might be using a JOIN in you
SQL call.  This could lead to multiple lines.

Start investigating your SQL statement I would suggest.


   Actually, it looks like this is the system I started writing out
for him a week or two ago, and unless he changed the SQL queries,
there were no JOINs in there.

   Jason, just to be sure, can you include the SQL query being sent,
first with the PHP variables (if any), then with the actual translated
SQL?



Hey Jim,

You're right it is the system you helped me get started with, Just  
wanted to add a little color coding for the different levels :)


Here is the sql query:

$sql  = SELECT * FROM tasks WHERE completed='0' order by id;
$sql .=  AND (day_of_week BETWEEN '0' AND '.$dow.');

And if I understand what you are looking for:

$sql = SELECT ALL from tasks where completed=NO order by id and  
(Day_of_week between the start of the week and today);


The code I had worked out, originally was something along the lines of:

if($row[5] ==Level1) (
echo TRTD bgcolor=.$Level1.$row[0] /td;
echo td bgcolor=.$Level1.$row[1]  /td;
echo td bgcolor=.$Level1.A href='$row[2]'Instructions/A/td;
	echo TD bgcolor=.$Level1.A href='update.php?taskid=$row 
[0]'Click here!/A;

}

if($row[5] ==Level2){
echo TRTD bgcolor=.$Level2.$row[0] /td;
echo td bgcolor=.$Level2.$row[1]  /td;
echo td bgcolor=.$Level2.A href='$row[2]'Instructions/A/td;
	echo TD bgcolor=.$Level2.A href='update.php?taskid=$row 
[0]'Click here!/A;


{
else
{
echo TRTD bgcolor=.$unclassified.$row[0] /td;
echo td bgcolor=.$unclassified.$row[1]  /td;
	echo td bgcolor=.$unclassified.A href='$row[2]'Instructions/ 
A/td;
	echo TD bgcolor=.$unclassified.A href='update.php?taskid=$row 
[0]'Click here!/A;


}

and what would happen is if $row[5] ==Level1 it would change the  
color to yellow, but then it would also display another line of the  
same info that would have the $unclassified color assigned to it.


What I have now though which Jim suggested is:

if ($row[5] ==Level1){
$rowColor = $Level1;
}

etc
 etc

echo TRTD bgcolor=.$rowColor.$row[0] /td;
echo td bgcolor=.$rowColor.$row[1]  /td;
	echo td bgcolor=.$rowColor.A href='$row[2]'Instructions/A/ 
td;
	echo TD bgcolor=.$rowColor.A href='update.php?taskid=$row 
[0]'Click here!/A;



which works great, I was just curious as to what was killing the  
original if statement and making it process the else statement when  
the IF matched...






   For example:

   $sql = SELECT task_id FROM tasks WHERE
task_id='.$_POST['taskid'].' LIMIT 0,30;;

   SELECT task_id FROM tasks WHERE task_id='24' LIMIT 0,30;

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107



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



Re: [PHP] If statement duplicating mysql records?

2007-06-20 Thread Daniel Brown

On 6/20/07, Jason Pruim [EMAIL PROTECTED] wrote:

Hey Jim,

You're right it is the system you helped me get started with, Just
wanted to add a little color coding for the different levels :)

Here is the sql query:

$sql  = SELECT * FROM tasks WHERE completed='0' order by id;
$sql .=  AND (day_of_week BETWEEN '0' AND '.$dow.');


   Sure, give Jim the credit.  Now you're uninvited from the wedding!  ;-P

   Try rewriting your SQL query:
   $sql  = SELECT * FROM tasks WHERE completed='0';
   $sql .=  AND (day_of_week BETWEEN '0' AND '.$dow.');
   $sql .=  ORDER BY id;

   Looks like you even kept the variables and statements pretty much
the same.  Glad to see it's working out for you out-of-the-box, for
the most part.

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

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



Re: [PHP] If statement duplicating mysql records?

2007-06-19 Thread Jim Lucas

Jason Pruim wrote:
Okay, so I have a question... Probably pretty easy, but why would my if 
statement show more records then what are in the database?


if($row[5] =='Level4'){ // White Highlight
echo TRTD bgcolor=.$Level4.$row[0] /td;
echo td bgcolor=.$Level4.$row[1]  /td;
echo td bgcolor=.$Level4.A href 
='$row[2]'Instructions/A/td;
echo TD bgcolor=.$Level4.A 
href='update.php?taskid=$row[0]'Click here!/A;

}// End of Level 4
   
   
   
else
   
{// Green Highlight

echo TRTD bgcolor=.$unclassified.$row[0] /td;
echo td bgcolor=.$unclassified.$row[1]  /td;
echo td bgcolor=.$unclassified.A href 
='$row[2]'Instructions/A/td;
echo TD bgcolor=.$unclassified.A 
href='update.php?taskid=$row[0]'Click here!/A;
   
}// End of Unclassified




Why not do it this way instead.

while( $row = mysql_fetch_array($results) ) {

$rowColor = $unclassified;

// White Highlight
if($row[5] =='Level4'){
$rowColor = $Level4;
}

echo TRTD bgcolor=.$rowColor.$row[0] /td;
echo td bgcolor=.$rowColor.$row[1]  /td;
echo td bgcolor=.$rowColor.A 
href='$row[2]'Instructions/A/td;
echo TD bgcolor=.$rowColor.A href='update.php?taskid=$row[0]'Click 
here!/A;

}




If I have a record that matches Level4 it will display both with the 
$Level4 color and the $unclassified color. Ideally it would only show up 
under the $Level4 category if it's Level4...  If that makes sense.


Or is there a better way to do it?

Thanks! :)

And one of these days, I WILL be able to help answer questions on this 
list too! :)


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




--
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare

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



Re: [PHP] PDO statement/resultset

2006-12-17 Thread Chris

David Duong wrote:

Hi everyone,

Let me know if there is a better place to post this.

I am playing with the idea of creating a true (KISS) abstraction layer 
that makes full use of PHP5's OOP support. So logically it would make 
sense to make use PDO wherever possible, however, one of PDO's design 
decisions was to make a prepared statement object also a result set 
(another question: ... why?) a script can not make use of the a 
statement more than once without completely fetching all the data it 
needs from the first query, before executing the next.


A likely scenario is that the prepared statement is executed and then 
before the script is done with processing the result, the same statement 
(with different binds) will need to be executed again, also using the 
result set from that statement.


Does PDO provide a method to deal with this problem? From what I 
understand the only solution would be to prepare a new statement for 
each query, even for queries with the same structure which defeats the 
purpose of a prepared statement(?) Is there a solution that is a bit 
better?


I don't think anyone understands exactly what you're trying to achieve.

Can you prepare 1 statement then use 2 different sets or parameters to 
call it?


Of course - but as you have noticed, the 1st result set has to be used 
before you can use the 2nd.


Why do you want to be able to do it another way? Are you trying to run 
queries in parallel (forking, whatever)? Are you trying to do things in 
a loop? Explain what you're trying to do and you might get a better 
response.


--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] if statement with or comparison (newbie)

2006-09-11 Thread Curt Zirzow

On 9/8/06, Robert Cummings [EMAIL PROTECTED] wrote:

On Fri, 2006-09-08 at 15:30 -0600, Jeremy Privett wrote:
 Well, it could be this, too:

 switch( $_REQUEST['id'] ) {
   case white:
   echo Right color.;
   break;

   case black:
   echo Right color.;
   break;

   default:
   echo Wrong color.;
   break;
 }

Ugh, if you're going to use a big ugly case statement for something so
trivial at least make use of the fall-through feature:

?php
switch( $_REQUEST['id'] )
{
case 'white':
case 'black':
{
echo 'Right color.';
break;
}


I don't know about big and ugly, it seems more clear on what is going
on in this situation. But yeah it is best to clearify the switch as
you rewrote it.

curt.

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



Re: [PHP] if statement with or comparison (newbie)

2006-09-09 Thread Satyam
No, just try it.   Since the returned value cannot have to values at once, 
whatever it comes it will succeed either one or both and being joined by an 
or, any single one that succeeds make the whole succeed.  Just try it:


Returned valueresult
redtrue or true = true
blackfalse or true = true
whitetrue or false = true

That is why in my e-mail  I insisted that the best thing you can do with 
complex booleans is try to straighten the logic and avoid too many 
negations, which tend to turn the logic upside down.


Satyam

- Original Message - 
From: Kevin Murphy [EMAIL PROTECTED]

To: php php-general@lists.php.net
Cc: JD [EMAIL PROTECTED]
Sent: Friday, September 08, 2006 11:25 PM
Subject: Re: [PHP] if statement with or comparison (newbie)



Shouldn't that be this instead:


 if (($_REQUEST['id'] != black) OR ($_REQUEST['id'] !=
white)) {

 echo wrong color;

 } else {

 echo right color;

 }


--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326


On Sep 8, 2006, at 2:28 PM, Prathaban Mookiah wrote:


Let me rephrase it. Your color should be black or white to be the
right
colour. Is this correct?

In that case you should change it to

 if ($_REQUEST['id'] != black AND $_REQUEST['id'] != white) {

 echo wrong color;

 } else (

 echo right color;

 }

- Original Message -
From: JD [EMAIL PROTECTED]
To: php-general@lists.php.net
Sent: Friday, September 08, 2006 5:03 PM
Subject: [PHP] if statement with or comparison (newbie)



I'm trying to set up a simple conditional, something like this:

If my_variable is NOT equal to (black or white)
   echo wrong color
else
   echo right color

Here is what I have tried:

if ($_REQUEST['id'] != (black or white)) {

echo wrong color;

} else (

echo right color;

)

However, no matter what I enter, I always get response right color.

I should add that if I change the if statement to:

if ($_REQUEST['id'] != (black))

then I get right color when I enter black and wrong color for
everything else.

Would you please point out what's the trivial thing I'm missing
here...

jd

--
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






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



Re: [PHP] if statement with or comparison (newbie)

2006-09-09 Thread Mark Charette

Robert Cummings wrote:

On Fri, 2006-09-08 at 18:38 -0400, tedd wrote:
  

At 5:03 PM -0400 9/8/06, JD wrote:

In all of the answers given thus far, no one mentioned that the use 
of $_REQUEST has a security issue with regard to where the $_REQUEST 
originated.


$_REQUEST is an array consisting of $_GET, $_POST and $_COOKIE values 
and as such, you don't know where the data came from and that might 
be important.


So, wouldn't it be better to recommend that the poster use $_GET, 
$_POST, or $_COOKIE instead of $_REQUEST?



Nope, not inherently less secure. If you are properly cleaning and
validating your data (as every good program should) then it doesn't
matter whether you pull from $_GET, $_POST, or $_REQUEST. The only time
it's bad is if you make assumptions about the value received -- AND YOU
SHOULD NEVER ASSUME YOU HAVE CLEAN DATA FROM AN OUTSIDE SOURCE!!
  
However, looking at it from a 'knowing early the data is tainted' 
perspective, not from a 'validating and cleaning perspective', if you 
have coded that (for instance) a variable is set via COOKIE, then only 
looking for that variable set via COOKIE will eliminate its being 
tainted by being set via GET or REQUEST. It doesn't eliminate any need 
for validation or cleaning, but reduces (naive) attempts to set via 
incorrect means. That is not possible via REQUEST. Personally, I like to 
toss out possibilities of bad data via simple means as early in the 
chain as possible.


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



Re: [PHP] if statement with or comparison (newbie)

2006-09-09 Thread Stut

Mark Charette wrote:
However, looking at it from a 'knowing early the data is tainted' 
perspective, not from a 'validating and cleaning perspective', if you 
have coded that (for instance) a variable is set via COOKIE, then only 
looking for that variable set via COOKIE will eliminate its being 
tainted by being set via GET or REQUEST. It doesn't eliminate any need 
for validation or cleaning, but reduces (naive) attempts to set via 
incorrect means. That is not possible via REQUEST. Personally, I like to 
toss out possibilities of bad data via simple means as early in the 
chain as possible.


If I understood that right it's a shocking naive statement for any 
developer to make. While I agree with what you're saying, you're 
implying a bad attitude to handling data from untrusted sources.


It shouldn't matter how difficult it is for the user to send you dodgy 
data... if its source is outside your control you need to handle it 
accordingly no matter how unlikely you think it is that it will be 
changed between you setting it and getting it back.


Data from any of the superglobals should be treated the same - trust 
none of them!!


-Stut

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



Re: [PHP] if statement with or comparison (newbie)

2006-09-09 Thread Robert Cummings
On Sat, 2006-09-09 at 10:21 -0400, Mark Charette wrote:
 Robert Cummings wrote:
  On Fri, 2006-09-08 at 18:38 -0400, tedd wrote:

  At 5:03 PM -0400 9/8/06, JD wrote:
  
  In all of the answers given thus far, no one mentioned that the use 
  of $_REQUEST has a security issue with regard to where the $_REQUEST 
  originated.
 
  $_REQUEST is an array consisting of $_GET, $_POST and $_COOKIE values 
  and as such, you don't know where the data came from and that might 
  be important.
 
  So, wouldn't it be better to recommend that the poster use $_GET, 
  $_POST, or $_COOKIE instead of $_REQUEST?
  
 
  Nope, not inherently less secure. If you are properly cleaning and
  validating your data (as every good program should) then it doesn't
  matter whether you pull from $_GET, $_POST, or $_REQUEST. The only time
  it's bad is if you make assumptions about the value received -- AND YOU
  SHOULD NEVER ASSUME YOU HAVE CLEAN DATA FROM AN OUTSIDE SOURCE!!

 However, looking at it from a 'knowing early the data is tainted' 
 perspective, not from a 'validating and cleaning perspective', if you 
 have coded that (for instance) a variable is set via COOKIE, then only 
 looking for that variable set via COOKIE will eliminate its being 
 tainted by being set via GET or REQUEST. It doesn't eliminate any need 
 for validation or cleaning, but reduces (naive) attempts to set via 
 incorrect means. That is not possible via REQUEST. Personally, I like to 
 toss out possibilities of bad data via simple means as early in the 
 chain as possible.

Any malevolently intentioned hacker will have little properly screwing
around with cookie data. I'm pretty sure browsers allow editing the
cookie values via the cookie browser. And if not, a quick PHP script is
just as simple to create that mucks with cookie data.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] if statement with or comparison (newbie)

2006-09-09 Thread Mark Charette

Stut wrote:

Mark Charette wrote:
However, looking at it from a 'knowing early the data is tainted' 
perspective, not from a 'validating and cleaning perspective', if you 
have coded that (for instance) a variable is set via COOKIE, then 
only looking for that variable set via COOKIE will eliminate its 
being tainted by being set via GET or REQUEST. It doesn't eliminate 
any need for validation or cleaning, but reduces (naive) attempts to 
set via incorrect means. That is not possible via REQUEST. 
Personally, I like to toss out possibilities of bad data via simple 
means as early in the chain as possible.


If I understood that right it's a shocking naive statement for any 
developer to make. While I agree with what you're saying, you're 
implying a bad attitude to handling data from untrusted sources.
I am being neither shocking or naive. Why is early discarding of data 
because it comes in the wrong area shocking? If I were looking for a 
variable set via a COOKIE, why would I look for the variable set via 
GET? As I so explicitly said above It doesn't eliminate any need for 
validation or cleaning, but reduces (naive) attempts to set via 
incorrect means. My CPU resources are valuable; writing code that 
checks whether a variable is set via the correct method is no harder 
($_COOKIE vs. $_REQUEST) and throws out trivially spurious data. No 
more, no less. The same checks still need apply after that, but my CPU 
won't be burdened by the script kiddies. No more, no less. The data just 
won't appear.


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



Re: [PHP] if statement with or comparison (newbie)

2006-09-09 Thread Robert Cummings
On Sat, 2006-09-09 at 11:30 -0400, Mark Charette wrote:
 Stut wrote:
  Mark Charette wrote:
  However, looking at it from a 'knowing early the data is tainted' 
  perspective, not from a 'validating and cleaning perspective', if you 
  have coded that (for instance) a variable is set via COOKIE, then 
  only looking for that variable set via COOKIE will eliminate its 
  being tainted by being set via GET or REQUEST. It doesn't eliminate 
  any need for validation or cleaning, but reduces (naive) attempts to 
  set via incorrect means. That is not possible via REQUEST. 
  Personally, I like to toss out possibilities of bad data via simple 
  means as early in the chain as possible.
 
  If I understood that right it's a shocking naive statement for any 
  developer to make. While I agree with what you're saying, you're 
  implying a bad attitude to handling data from untrusted sources.

 I am being neither shocking or naive. Why is early discarding of data 
 because it comes in the wrong area shocking?

That's your last line, I think he's commenting on the rest of your
comment. Questionable data is questionable data, it doesn't matter from
whence you clean it. If you haven't cleaned it your still going to get
screwed no matter how much you rely on it being difficult to manipulate
by a site visitor.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] if statement with or comparison (newbie)

2006-09-09 Thread Mark Charette

Robert Cummings wrote:

On Sat, 2006-09-09 at 11:30 -0400, Mark Charette wrote:
  

Stut wrote:


Mark Charette wrote:
  
However, looking at it from a 'knowing early the data is tainted' 
perspective, not from a 'validating and cleaning perspective', if you 
have coded that (for instance) a variable is set via COOKIE, then 
only looking for that variable set via COOKIE will eliminate its 
being tainted by being set via GET or REQUEST. It doesn't eliminate 
any need for validation or cleaning, but reduces (naive) attempts to 
set via incorrect means. That is not possible via REQUEST. 
Personally, I like to toss out possibilities of bad data via simple 
means as early in the chain as possible.

If I understood that right it's a shocking naive statement for any 
developer to make. While I agree with what you're saying, you're 
implying a bad attitude to handling data from untrusted sources.
  


  
I am being neither shocking or naive. Why is early discarding of data 
because it comes in the wrong area shocking?



That's your last line, I think he's commenting on the rest of your
comment. Questionable data is questionable data, it doesn't matter from
whence you clean it. If you haven't cleaned it your still going to get
screwed no matter how much you rely on it being difficult to manipulate
by a site visitor.
  
Where am I being unclear, then? reduces (naive) attempts to set via 
incorrect means. doesn't say 'eliminate serious attempts'. I would 
think my statement It doesn't eliminate any need for validation or 
cleaning,  covers the remaining scenarios. Indeed, determining the 
source of data is one of the essential steps in validation. The one of 
the rules is 'discard even valid data if it comes from an untrusted 
source - and data coming from an _incorrect_ source is, by definition, 
untrusted even if if you wish to expend the effort to prove it valid.


And I'll wager a brew no one here has ever done a formal, mathematically 
rigorous proof of a validation routine except as a class project. As a 
senior member of the software QC department in a major industrial 
company, I generally find more errors and omissions in validation 
routines during code reviews and ethical hacks than anywhere else.


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



Re: [PHP] if statement with or comparison (newbie)

2006-09-09 Thread Stut

Mark Charette wrote:
And I'll wager a brew no one here has ever done a formal, mathematically 
rigorous proof of a validation routine except as a class project. As a 
senior member of the software QC department in a major industrial 
company, I generally find more errors and omissions in validation 
routines during code reviews and ethical hacks than anywhere else.


Ok, let's not turn this into a pissing contest. I admit I misread the 
initial email and read more into it than it said. However, since this is 
a mailing list with a lot of beginners on it we usually make a point to 
be very clear on issues like validation and it was worth reiterating the 
point that no data that comes from the user should not be trusted no 
matter how hard it is for the user to change.


Your point is valid, but in the great scheme of things it's more 
important to enforce the importance of validation than performance. I 
felt your post was confusing so I'm sure others did too.


'Nuff pissing.

-Stut

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



Re: [PHP] if statement with or comparison (newbie)

2006-09-09 Thread Robert Cummings
On Sat, 2006-09-09 at 12:12 -0400, Mark Charette wrote:

 As a senior member of the software QC department in a major industrial 
 company, I generally find more errors and omissions in validation 
 routines during code reviews and ethical hacks than anywhere else.

http://en.wikipedia.org/wiki/Appeal_to_authority

Where's Tedd, he's got the latin to go with the above link :)

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] if statement with or comparison (newbie)

2006-09-09 Thread Robert Cummings
On Sat, 2006-09-09 at 17:27 +0100, Stut wrote:
 Mark Charette wrote:
  And I'll wager a brew no one here has ever done a formal, mathematically 
  rigorous proof of a validation routine except as a class project. As a 
  senior member of the software QC department in a major industrial 
  company, I generally find more errors and omissions in validation 
  routines during code reviews and ethical hacks than anywhere else.
 
 Ok, let's not turn this into a pissing contest. I admit I misread the 
 initial email and read more into it than it said. However, since this is 
 a mailing list with a lot of beginners on it we usually make a point to 
 be very clear on issues like validation and it was worth reiterating the 
 point that no data that comes from the user should not be trusted no 
 matter how hard it is for the user to change.
 
 Your point is valid, but in the great scheme of things it's more 
 important to enforce the importance of validation than performance. I 
 felt your post was confusing so I'm sure others did too.
 
 'Nuff pissing.

A, what about this bonfire I was putting out?? Admittedly there's a
strong odour hanging in the air now, but we don't want forest fires do
we? *heheh*

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] if statement with or comparison (newbie)

2006-09-09 Thread tedd

At 12:29 PM -0400 9/9/06, Robert Cummings wrote:

On Sat, 2006-09-09 at 12:12 -0400, Mark Charette wrote:


 As a senior member of the software QC department in a major industrial
 company, I generally find more errors and omissions in validation
 routines during code reviews and ethical hacks than anywhere else.


http://en.wikipedia.org/wiki/Appeal_to_authority

Where's Tedd, he's got the latin to go with the above link :)

Cheers,
Rob.


Rob:

Don't throw me in that briar patch. I know the 
saying Locus ab auctoritate est infirmissimus 
may appear to fit, but I think in this case se 
méfier de l'eau qui dort is better.


Besides:

A) I was the one that started this fire storm.

B) Mark came in and backed me up.

C) Stu, who respect greatly, surprisingly waded in on the other side.

Now, I stand cowardly between two opinions not 
wanting to offend either, nor embarrass myself 
publicly, which I do often enough anyway.


However with that said, my original question/statement still stands.

I realize (AS WE ALL DO), that *all* data coming 
from outside *must* be sanitized -- BUT -- using 
$_REQUEST still does not provide as much 
information as to where the data came from as the 
use of $_GET, $_POST, and $_COOKIE -- that's an 
unarguable fact, is it not?


This thread was like an old-west circled wagon 
train with everyone inside expounding about the 
obvious dangers of an Indian attack* but failing 
to listen to some who are saying They're 
attacking from the West, while arguing it's not 
important to know which way the attack comes. I 
think some just misread the point of the post.


tedd (as he scurries around to the east side of a rock while dodging arrows)

*In keeping with current Political correctness, 
it was an US Indian attack -- also note the 
attack was from the West and not from the East. 
:-)


--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] if statement with or comparison (newbie)

2006-09-08 Thread Prathaban Mookiah
Let me rephrase it. Your color should be black or white to be the right 
colour. Is this correct?

In that case you should change it to

 if ($_REQUEST['id'] != black AND $_REQUEST['id'] != white) {

 echo wrong color;

 } else (

 echo right color;

 }

- Original Message - 
From: JD [EMAIL PROTECTED]
To: php-general@lists.php.net
Sent: Friday, September 08, 2006 5:03 PM
Subject: [PHP] if statement with or comparison (newbie)


 I'm trying to set up a simple conditional, something like this:

 If my_variable is NOT equal to (black or white)
echo wrong color
 else
echo right color

 Here is what I have tried:

 if ($_REQUEST['id'] != (black or white)) {

 echo wrong color;

 } else (

 echo right color;

 )

 However, no matter what I enter, I always get response right color.

 I should add that if I change the if statement to:

 if ($_REQUEST['id'] != (black))

 then I get right color when I enter black and wrong color for 
 everything else.

 Would you please point out what's the trivial thing I'm missing here...

 jd

 -- 
 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] if statement with or comparison (newbie)

2006-09-08 Thread Kevin Murphy

Shouldn't that be this instead:


 if (($_REQUEST['id'] != black) OR ($_REQUEST['id'] !=  
white)) {


 echo wrong color;

 } else {

 echo right color;

 }


--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326


On Sep 8, 2006, at 2:28 PM, Prathaban Mookiah wrote:

Let me rephrase it. Your color should be black or white to be the  
right

colour. Is this correct?

In that case you should change it to

 if ($_REQUEST['id'] != black AND $_REQUEST['id'] != white) {

 echo wrong color;

 } else (

 echo right color;

 }

- Original Message -
From: JD [EMAIL PROTECTED]
To: php-general@lists.php.net
Sent: Friday, September 08, 2006 5:03 PM
Subject: [PHP] if statement with or comparison (newbie)



I'm trying to set up a simple conditional, something like this:

If my_variable is NOT equal to (black or white)
   echo wrong color
else
   echo right color

Here is what I have tried:

if ($_REQUEST['id'] != (black or white)) {

echo wrong color;

} else (

echo right color;

)

However, no matter what I enter, I always get response right color.

I should add that if I change the if statement to:

if ($_REQUEST['id'] != (black))

then I get right color when I enter black and wrong color for
everything else.

Would you please point out what's the trivial thing I'm missing  
here...


jd

--
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] if statement with or comparison (newbie)

2006-09-08 Thread Mitch Miller

I think the OR should be an AND ...

If $_REQUEST['id'] = black then the second test will be true and it 
will output wrong color.  If the color is white then the same thing 
will happen 'cause it meets the first criteria.


-- Mitch


Kevin Murphy wrote:

Shouldn't that be this instead:


 if (($_REQUEST['id'] != black) OR ($_REQUEST['id'] !=  white)) {

 echo wrong color;

 } else {

 echo right color;

 }




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



RE: [PHP] if statement with or comparison (newbie)

2006-09-08 Thread Jeremy Privett
Well, it could be this, too:

switch( $_REQUEST['id'] ) {
case white:
echo Right color.;
break;

case black:
echo Right color.;
break;

default:
echo Wrong color.;
break;
}

---
Jeremy C. Privett
Director of Product Development
Zend Certified Engineer
Completely Unique
[EMAIL PROTECTED]
 
Phone: 303.459.4819
Fax: 303.459.4821
Web:www.completelyunique.com
 
This email may contain confidential and privileged material for the sole use
of the intended recipient. Any review or distribution by others is strictly
prohibited. If you are not the intended recipient please contact the sender
and delete all copies. Your compliance is appreciated.

-Original Message-
From: Kevin Murphy [mailto:[EMAIL PROTECTED] 
Sent: Friday, September 08, 2006 3:26 PM
To: php
Cc: JD
Subject: Re: [PHP] if statement with or comparison (newbie)

Shouldn't that be this instead:


  if (($_REQUEST['id'] != black) OR ($_REQUEST['id'] !=  
white)) {

  echo wrong color;

  } else {

  echo right color;

  }


-- 
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326


On Sep 8, 2006, at 2:28 PM, Prathaban Mookiah wrote:

 Let me rephrase it. Your color should be black or white to be the  
 right
 colour. Is this correct?

 In that case you should change it to

  if ($_REQUEST['id'] != black AND $_REQUEST['id'] != white) {

  echo wrong color;

  } else (

  echo right color;

  }

 - Original Message -
 From: JD [EMAIL PROTECTED]
 To: php-general@lists.php.net
 Sent: Friday, September 08, 2006 5:03 PM
 Subject: [PHP] if statement with or comparison (newbie)


 I'm trying to set up a simple conditional, something like this:

 If my_variable is NOT equal to (black or white)
echo wrong color
 else
echo right color

 Here is what I have tried:

 if ($_REQUEST['id'] != (black or white)) {

 echo wrong color;

 } else (

 echo right color;

 )

 However, no matter what I enter, I always get response right color.

 I should add that if I change the if statement to:

 if ($_REQUEST['id'] != (black))

 then I get right color when I enter black and wrong color for
 everything else.

 Would you please point out what's the trivial thing I'm missing  
 here...

 jd

 -- 
 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


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



Re: [PHP] if statement with or comparison (newbie)

2006-09-08 Thread Satyam


- Original Message - 
From: JD [EMAIL PROTECTED]

To: php-general@lists.php.net
Sent: Friday, September 08, 2006 11:03 PM
Subject: [PHP] if statement with or comparison (newbie)



I'm trying to set up a simple conditional, something like this:

If my_variable is NOT equal to (black or white)
   echo wrong color
else
   echo right color

Here is what I have tried:

if ($_REQUEST['id'] != (black or white)) {



What PHP (and any parser, for that matter) will try to do is first solve the 
innermost parenthesis.  (black or white).  Many typed languages would 
give an error at this point, but PHP tries to convert anything it gets to 
whatever is more useful at the moment.  Since both black and white are 
not null or empty strings, they are evaluated as true for the logical 
comparison and true or true is always true.  Now, $_REQUEST['id'] might be 
whatever it is, but dealing with booleans as we are this far, anything but 
missing or empty string will be true as well, which will give you the second 
option.



Now, first of all, avoid negative comparissons, negative booleans are 
horrible.  Try first to straighten them up or you might get thoroughly 
confussed:



if ($_REQUEST['id] == 'black' or $_REQUEST['id'] == 'white') {
   echo 'right color';
} else {
echo 'wrong color'';
}

And so as you know why it is good to straighten negative booleans, this 
would be the twisted way


if ($_REQUEST['id] != 'black' and $_REQUEST['id'] != 'white') {
echo 'wrong color'';
} else {
   echo 'right color';
}

Notice that not only the comparisson changed but now they are joined by an 
AND instead of an OR and the then and else parts are swapped.


Satyam



echo wrong color;

} else (

echo right color;

)

However, no matter what I enter, I always get response right color.

I should add that if I change the if statement to:

if ($_REQUEST['id'] != (black))

then I get right color when I enter black and wrong color for 
everything else.


Would you please point out what's the trivial thing I'm missing here...

jd

--
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] if statement with or comparison (newbie)

2006-09-08 Thread JD

At 05:30 PM 9/8/2006, you wrote:


- Original Message - From: JD [EMAIL PROTECTED]
To: php-general@lists.php.net
Sent: Friday, September 08, 2006 11:03 PM
Subject: [PHP] if statement with or comparison (newbie)



I'm trying to set up a simple conditional, something like this:

If my_variable is NOT equal to (black or white)
   echo wrong color
else
   echo right color

Here is what I have tried:

if ($_REQUEST['id'] != (black or white)) {


What PHP (and any parser, for that matter) will try to do is first solve 
the innermost parenthesis.  (black or white).  Many typed languages 
would give an error at this point, but PHP tries to convert anything it 
gets to whatever is more useful at the moment.  Since both black and 
white are not null or empty strings, they are evaluated as true for the 
logical comparison and true or true is always true.  Now, $_REQUEST['id'] 
might be whatever it is, but dealing with booleans as we are this far, 
anything but missing or empty string will be true as well, which will give 
you the second option.



Now, first of all, avoid negative comparissons, negative booleans are 
horrible.  Try first to straighten them up or you might get thoroughly 
confussed:



if ($_REQUEST['id] == 'black' or $_REQUEST['id'] == 'white') {
   echo 'right color';
} else {
echo 'wrong color'';
}

And so as you know why it is good to straighten negative booleans, this 
would be the twisted way


if ($_REQUEST['id] != 'black' and $_REQUEST['id'] != 'white') {
echo 'wrong color'';
} else {
   echo 'right color';
}

Notice that not only the comparisson changed but now they are joined by an 
AND instead of an OR and the then and else parts are swapped.


Satyam


Thank you all!

jd

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



RE: [PHP] if statement with or comparison (newbie)

2006-09-08 Thread Robert Cummings
On Fri, 2006-09-08 at 15:30 -0600, Jeremy Privett wrote:
 Well, it could be this, too:
 
 switch( $_REQUEST['id'] ) {
   case white:
   echo Right color.;
   break;
 
   case black:
   echo Right color.;
   break;
 
   default:
   echo Wrong color.;
   break;
 }

Ugh, if you're going to use a big ugly case statement for something so
trivial at least make use of the fall-through feature:

?php
switch( $_REQUEST['id'] )
{
case 'white':
case 'black':
{
echo 'Right color.';
break;
}

default:
{
echo 'Wrong color.';
}
}
?

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] if statement with or comparison (newbie)

2006-09-08 Thread tedd

At 5:03 PM -0400 9/8/06, JD wrote:

I'm trying to set up a simple conditional, something like this:

Here is what I have tried:

if ($_REQUEST['id'] != (black or white)) {



In all of the answers given thus far, no one mentioned that the use 
of $_REQUEST has a security issue with regard to where the $_REQUEST 
originated.


$_REQUEST is an array consisting of $_GET, $_POST and $_COOKIE values 
and as such, you don't know where the data came from and that might 
be important.


So, wouldn't it be better to recommend that the poster use $_GET, 
$_POST, or $_COOKIE instead of $_REQUEST?


Just an idea -- comments?

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] if statement with or comparison (newbie)

2006-09-08 Thread Robert Cummings
On Fri, 2006-09-08 at 18:38 -0400, tedd wrote:
 At 5:03 PM -0400 9/8/06, JD wrote:
 I'm trying to set up a simple conditional, something like this:
 
 Here is what I have tried:
 
  if ($_REQUEST['id'] != (black or white)) {
 
 
 In all of the answers given thus far, no one mentioned that the use 
 of $_REQUEST has a security issue with regard to where the $_REQUEST 
 originated.
 
 $_REQUEST is an array consisting of $_GET, $_POST and $_COOKIE values 
 and as such, you don't know where the data came from and that might 
 be important.
 
 So, wouldn't it be better to recommend that the poster use $_GET, 
 $_POST, or $_COOKIE instead of $_REQUEST?

Nope, not inherently less secure. If you are properly cleaning and
validating your data (as every good program should) then it doesn't
matter whether you pull from $_GET, $_POST, or $_REQUEST. The only time
it's bad is if you make assumptions about the value received -- AND YOU
SHOULD NEVER ASSUME YOU HAVE CLEAN DATA FROM AN OUTSIDE SOURCE!!

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] If statement question

2006-06-27 Thread Richard Lynch
On Mon, June 26, 2006 1:23 pm, Robert Cummings wrote:
 I can't think of any language that processes the contents of a
 conditional block when the test condition fails.

I believe that PHP with Runkit would let you set that up to happen, if
it was something you actually wanted... :-)

And Common Lisp will cheerfully let you re-define NIL so that all the
truth-values come out quite differently from what you expect, if you
want to be intentionally obfuscating code.

These are not, however, what one would consider normal operations

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] If statement question

2006-06-26 Thread Martin Marques

On Mon, 26 Jun 2006 19:10:59 +0100, Alex Major [EMAIL PROTECTED] wrote:
 Hi list.
 Basically, I'm still learning new things about php and I was wondering if
 things inside an if statement get 'looked at' by a script if the condition
 is false.
 For example, would this mysql query get executed if $number = 0 ?
 
 If ($number == 1) {
 mysql_query($blah)
 }

NO!

-- 
-
Lic. Martín Marqués |   SELECT 'mmarques' || 
Centro de Telemática|   '@' || 'unl.edu.ar';
Universidad Nacional|   DBA, Programador, 
del Litoral |   Administrador
-

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



Re: [PHP] If statement question

2006-06-26 Thread Robert Cummings
On Mon, 2006-06-26 at 14:10, Alex Major wrote:
 Hi list.
 Basically, I'm still learning new things about php and I was wondering if
 things inside an if statement get 'looked at' by a script if the condition
 is false.
 For example, would this mysql query get executed if $number = 0 ?
 
 If ($number == 1) {
 mysql_query($blah)
 }
 
 I know that's not really valid php, but hope it gets my point across. I was
 just wondering from an optimisation perspective, as I don't want sql
 commands being executed when they don't need to be (unnecessary server
 usage). 

I can't think of any language that processes the contents of a
conditional block when the test condition fails.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] If statement question

2006-06-26 Thread Larry Garfield
On Monday 26 June 2006 13:10, Alex Major wrote:
 Hi list.
 Basically, I'm still learning new things about php and I was wondering if
 things inside an if statement get 'looked at' by a script if the condition
 is false.
 For example, would this mysql query get executed if $number = 0 ?

 If ($number == 1) {
 mysql_query($blah)
 }

Nope.  That's the definition of an if statement (conditional), in any 
language.  If the text fails, the contents of the block never happen.  

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it.  -- Thomas 
Jefferson

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



Re: [PHP] select statement with variables ???

2005-12-21 Thread Robin Vickery
On 12/21/05, Anasta [EMAIL PROTECTED] wrote:
 Can someone tell me why this select is wrong please---ive tried everything.
 the $cat is the tablename .

You've tried *everything*  ?

Why do you think it's wrong? Did you get an error message of some kind?

What do you see if you echo $query? Are the values of $cat and $id
what you expected?

  -robin


RE: [PHP] select statement with variables ???

2005-12-21 Thread Jim Moseby
 
 Can someone tell me why this select is wrong please---ive 
 tried everything.
 the $cat is the tablename .
 
 
 $query= SELECT title FROM $cat WHERE id='$id';
 
 

Apparently, either $cat or $id is not the value you think it is.  First, I
would try changing

$result=mysql_query($query);

to read:

$result=mysql_query($query) or die(mysql_error());

This will, no doubt, lend some insight into where your error is.

JM

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



RE: [PHP] select statement with variables ???

2005-12-21 Thread Jay Blanchard
[snip]
 $query= SELECT title FROM $cat WHERE id='$id';
[/snip]

echo $query; // does it look right to you?
Alway throw an error when in question

if(!($result = mysql_query($query, $connection))){
   echo mysql_error() . br\n;
   exit();
}

My bet is that you need to concatenate

$query = SELECT title FROM  . $cat .  WHERE id = '. $id .' ;

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



Re: [PHP] select statement with variables ???

2005-12-21 Thread Jochem Maas

side-question
Jay how come you though concating would give
a different result to interpolation?
/side-question

Jay Blanchard wrote:

[snip]


$query= SELECT title FROM $cat WHERE id='$id';


[/snip]

echo $query; // does it look right to you?
Alway throw an error when in question

if(!($result = mysql_query($query, $connection))){
   echo mysql_error() . br\n;
   exit();
}



up to here I agree with Jay 100%, especially the 'echo' part (also get
familiar with var_dump() and print_r() functions to help debug your problems...


My bet is that you need to concatenate

$query = SELECT title FROM  . $cat .  WHERE id = '. $id .' ;


now unless either $cat or $id is actually an object with a 'magic'
__toString() method defined and the engine has been changed to fully/properly
support 'magic' object2string casting I don't agree that concat'ing will help
(even all of what I sAid was true I don't think it would help either),
the reaosn being that AFAICT the following 2 statements leave you with the same
string:


$cat = mytable;
$id  = 1234;
$one = SELECT title FROM $cat WHERE id='$id';
$two = SELECT title FROM .$cat. WHERE id = '.$id.';

var_dump( ($one === $two) ); // -- will show you that this equates to TRUE.

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



RE: [PHP] select statement with variables ???

2005-12-21 Thread Jay Blanchard
[snip]
side-question
Jay how come you though concating would give
a different result to interpolation?
/side-question
[/snip]

It is not really a different result, it is just something that I am in the
habit of doing. The concat or not to concat question has fueled many a
holy war. I concat, others do not. I am used to seeing it and looking for it
in code. Others think that it adds too much junk.

[snip]
 My bet is that you need to concatenate

...I don't agree that concat'ing will help...
[/snip]

I probably shouldn't have used bet...I just should have suggested it.

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



Re: [PHP] select statement with variables ???

2005-12-21 Thread Jochem Maas

Jay Blanchard wrote:

[snip]
side-question
Jay how come you though concating would give
a different result to interpolation?
/side-question
[/snip]

It is not really a different result, it is just something that I am in the
habit of doing. The concat or not to concat question has fueled many a
holy war. I concat, others do not. I am used to seeing it and looking for it
in code. Others think that it adds too much junk.


I see - personally I don't give a  about this holy war; I use both
pretty interchangably - depends on the context what I think looks neater.

tangent
it is my believe the technically this:

echo $a, $b, $c;

is (should be) faster than:

echo $a . $b . $c;

can anyone confirm this to be true?
/tangent



[snip]


My bet is that you need to concatenate



...I don't agree that concat'ing will help...
[/snip]

I probably shouldn't have used bet...I just should have suggested it.


I still stand by the fact that whether you bet or suggest the OP would end up
with the same broken query string.

now the hint about using ECHO .. that you could have written in 40 foot high 
letters :-)





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



RE: [PHP] if statement help

2005-11-04 Thread Ford, Mike
On 03 November 2005 15:26, Brent Baisley wrote:

 You only need one if. The parenthesis will evaluation order.
 
 if( ( !empty( $var1 )  || ( !empty( $var2 )  !empty( $var3 ) ) ||
 $var1 == something  ) 

However, the $var1==something test is redundant in this, since if that is 
true the !empty($var1) test will also be true and the rest of the test will not 
be evaluated.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 


To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

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



Re: [PHP] if statement help

2005-11-03 Thread Brent Baisley

You only need one if. The parenthesis will evaluation order.

if( ( !empty( $var1 )  || ( !empty( $var2 )  !empty( $var3 ) ) ||  
$var1 == something  )


On Nov 3, 2005, at 10:13 AM, Jason Gerfen wrote:

I am trying to determine if it is worth my time to attempt a if  
statement similar to the following.  I am asking because I have not  
found any references to something like this:


if( ( !empty( $var1 ) ) || ( if( !empty( $var2 ) )  ( !empty 
( $var3 ) ) ) || ( $var1 == something ) ) {

// do something fancy
}

--
Jason Gerfen

My girlfriend threated to
leave me if I went boarding...
I will miss her.
~ DIATRIBE aka FBITKK

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





--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search  Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577

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



Re: [PHP] conditional statement inside while loop?

2005-09-02 Thread z a p a n
Murray, Miles, Cristea  Jim: Thanks a lot, I got it figured out.  Peace, -z

 Hello everyone,
 
 I'm using a while loop to display a list of people contained in my
 database.
 I'd like to assign different font colors to each depending on which city
 they're from, but I can't seem to get an if/elseif/else statement to work
 inside the while loop.  Is there another way to do this?
 
 Hi Zach,
 
 There should be no reason why you can't use if/elseif/else within your while
 loop. The fact that you're experiencing problems strongly suggests that you
 have a combination of conditionals in your if/elseif/else that is
 effectively ignoring the data being returned from your recordset.
 
 It may be something as simple as using = in your if statement instead of
 == (ie, so the conditional is always true, because you're using the
 assignment = operator instead of the evaluative == operator), or a
 combination of conditions, each of which are accurate but which when placed
 together cause problems.
 
 To get an idea where your problem is occurring, try going from simple to
 complex. Start with something like the following pseudo-code:
 
 while ($row = get_data_from_your_recordset){
 if (strlen($row['a_recordset_field'])  0){
 echo Data found:  . $row['a_recordset_field'] . br /;
 } else {
 echo Data not foundbr /;
 }
 }
 
 The assumption being made above is that you will be using a field from your
 recordset that contains data that is ordinarily longer than 0 bytes.
 
 Doing the above will demonstrate that at the very least you are returning a
 valid recordset and that conditional statements work within while loops. If
 even this fails, then check the SQL that is being used to populate the
 recordset, and make sure that you are using the same field names in your PHP
 code as is being returned from the table by the recordset.
 
 Once the above is working, add back in your actual conditional(s), one by
 one. You're looking for the point where 'working' code becomes 'broken'
 code. Most of the time when you debug in this way it becomes obvious why the
 code isn't behaving the way you expect it to. If there's still any confusion
 at that point, at least you will be in a better position to supply actual
 code to the list, so we can work out the real problem.
 
 Much warmth,
 
 Murray
 ---
 Lost in thought...
 http://www.planetthoughtful.org


-- 

fourthcity 2005 ; slow yr roll. --- http://www.fourthcity.net/


 quick links:
 http://www.fourthcity.net/   [fct]
 http://www.zapan.net/[  zapan]
 http://www.laptopbattle.org/ [ battle]
 http://www.postermidget.com/ [ midget]


  +
   +
 +
 + +
 +
 +


 much love! from the fourthcity studios  

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



RE: [PHP] conditional statement inside while loop?

2005-09-01 Thread Jim Moseby
 I'm using a while loop to display a list of people contained 
 in my database.
 I'd like to assign different font colors to each depending on 
 which city
 they're from, but I can't seem to get an if/elseif/else 
 statement to work
 inside the while loop.  Is there another way to do this?

Something like this maybe?:

pseoudcode
while($row=mysql_fetch_array($result){
  switch($row['city']){
case 'bejing':
  $bgcolor='#FF';
  break;
case 'tokyo':
   $bgcolor='#00FF00';
   break;
{...}
  }//switch
}//while
/pseoudcode

JM

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



Re: [PHP] conditional statement inside while loop?

2005-09-01 Thread Miles Thompson

At 03:52 PM 9/1/2005,  z a p a n  wrote:

Hello everyone,

I'm using a while loop to display a list of people contained in my database.
I'd like to assign different font colors to each depending on which city
they're from, but I can't seem to get an if/elseif/else statement to work
inside the while loop.  Is there another way to do this?

Thanks in advance,
Zach


That should work, just try a simple if() at first. If it is not working, 
back up, simplify, just do  simple echo to tell you where you are.


Better yet, this sounds like an excellent spot to use switch ... case ... 
break.


If you have an editor that can match braces take advantage of that feature. 
You may not be exactly where you think you are.


So, no answer, but hopefully the suggestions are helpful.

Cheers - Miles 


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



RE: [PHP] conditional statement inside while loop?

2005-09-01 Thread Murray @ PlanetThoughtful
 Hello everyone,
 
 I'm using a while loop to display a list of people contained in my
 database.
 I'd like to assign different font colors to each depending on which city
 they're from, but I can't seem to get an if/elseif/else statement to work
 inside the while loop.  Is there another way to do this?

Hi Zach,

There should be no reason why you can't use if/elseif/else within your while
loop. The fact that you're experiencing problems strongly suggests that you
have a combination of conditionals in your if/elseif/else that is
effectively ignoring the data being returned from your recordset.

It may be something as simple as using = in your if statement instead of
== (ie, so the conditional is always true, because you're using the
assignment = operator instead of the evaluative == operator), or a
combination of conditions, each of which are accurate but which when placed
together cause problems.

To get an idea where your problem is occurring, try going from simple to
complex. Start with something like the following pseudo-code:

while ($row = get_data_from_your_recordset){
if (strlen($row['a_recordset_field'])  0){
echo Data found:  . $row['a_recordset_field'] . br /;
} else {
echo Data not foundbr /;
}
}

The assumption being made above is that you will be using a field from your
recordset that contains data that is ordinarily longer than 0 bytes.

Doing the above will demonstrate that at the very least you are returning a
valid recordset and that conditional statements work within while loops. If
even this fails, then check the SQL that is being used to populate the
recordset, and make sure that you are using the same field names in your PHP
code as is being returned from the table by the recordset.

Once the above is working, add back in your actual conditional(s), one by
one. You're looking for the point where 'working' code becomes 'broken'
code. Most of the time when you debug in this way it becomes obvious why the
code isn't behaving the way you expect it to. If there's still any confusion
at that point, at least you will be in a better position to supply actual
code to the list, so we can work out the real problem.

Much warmth,

Murray
---
Lost in thought...
http://www.planetthoughtful.org

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



Re: [PHP] select statement

2005-05-08 Thread Andy Pieters
On Thursday 05 May 2005 10:10, Anasta wrote:
 Why doesnt this work, it shows the username but not the balance of the
 users money.here is the mysql table:

 ?php session_start();
 include(connect.php);
 $uname=$_SESSION['username'];
 $user_balance=mysql_query($sql);
 $sql = Select  FROM users ,user_balance WHERE user_id =$uname;
 $result = mysql_query();

 ?
 ?php echo $uname;?br
 ?php echo $user_balance;?


Hi Anasta

In your code, when you issue the mysql_query command the first time, the 
variable $sql is still empty.

You should rewrite your script like this:
?php
session_start();
require('connect.php'); 
$uname=mysql_escape_string($_SESSION['username'];
$sql=   SELECT *
FROM `users`, `user_balance`
WHERE `user_id`='$uname';;
$result=mysql_query($sql) or die('Database Error'); 
if(is_resource($result))
if(mysql_num_rows($result0))
{
$data=mysql_fetch_assoc($result);
mysql_free_result($result);
$user_balance=$data['user_balance'];
$found=true;
}
if(!(isset($found))
echo Sorry, I could not find a record for user id $uname;
else
{
echo User: $unamebr
 Balance:   $user_balancebr;
}
?

Notes: 
* just because it comes from SESSION doesn't mean that it cannot be spoofed.  
That's why you should escape uname before including it in a query.
* in mysql commands, it is better to explicitally specify the resource link 
identifier you obtained when you opened the connection 
($link=mysql_connect(...))
* if you include a critical script, better use 'require' because it will cause 
php to stop parsing the page if it cannot find the script.


With kind regards

Andy
-- 
Registered Linux User Number 379093
-- --BEGIN GEEK CODE BLOCK-
Version: 3.1
GAT/O/E$ d-(---)+ s:(+): a--(-)? C$(+++) UL$ P-(+)++
L+++$ E---(-)@ W++$ !N@ o? !K? W--(---) !O !M- V-- PS++(+++)
PE--(-) Y+ PGP++(+++) t+(++) 5-- X++ R*(+)@ !tv b-() DI(+) D+(+++) G(+)
e$@ h++(*) r--++ y--()
-- ---END GEEK CODE BLOCK--
--
Check out these few php utilities that I released
 under the GPL2 and that are meant for use with a 
 php cli binary:
 
 http://www.vlaamse-kern.com/sas/
--

--

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



Re: [PHP] select statement

2005-05-08 Thread Josip Dzolonga
On , 2005-05-08 at 23:16 +0200, Andy Pieters wrote:
 Notes: 
 * just because it comes from SESSION doesn't mean that it cannot be spoofed.  
 That's why you should escape uname before including it in a query.

Is there something I do not know ? :). As far as I know, it can be
spoofed only if you have access to session data, which is held on the
server-side, so only someone with server access can spoof. Any other way
of doing it ?

Josip Dzolonga
http://josip.dotgeek.org

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



Re: [PHP] select statement

2005-05-08 Thread Richard Lynch
On Sun, May 8, 2005 3:20 pm, Josip Dzolonga said:
 On нед, 2005-05-08 at 23:16 +0200, Andy Pieters wrote:
 Notes:
 * just because it comes from SESSION doesn't mean that it cannot be
 spoofed.
 That's why you should escape uname before including it in a query.

 Is there something I do not know ? :). As far as I know, it can be
 spoofed only if you have access to session data, which is held on the
 server-side, so only someone with server access can spoof. Any other way
 of doing it ?

Are you on a shared server?

Then your session data is open to the other 199 clients on that server...

If you are *NOT* on a shared server, and if you are 100% confident that
nobody will ever compromise your server, and make your $_SESSION data a
priority to hack, well then, you're safe...

How much effort does it take to scrub your $_SESSION data, though?

What are you storing in there?

How Bad will it be if a Bad Guy breaks in and snarfs it?

Only you can answer these for a dedicated server/application.

Not scrubbing $_SESSION on a shared server...  That's just wrong, IMHO.

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] select statement

2005-05-05 Thread bala chandar
On 5/5/05, Anasta [EMAIL PROTECTED] wrote:
 Why doesnt this work, it shows the username but not the balance of the users
 money.here is the mysql table:
 
 CREATE TABLE `users` (
   `user_id` int(11) NOT NULL auto_increment,
   `username` varchar(15) NOT NULL default '',
   `password` varchar(15) NOT NULL default '',
   `status` varchar(10) NOT NULL default '',
   `user_balance` bigint(5) NOT NULL default '0',
   PRIMARY KEY  (`user_id`)
 ) TYPE=MyISAM AUTO_INCREMENT=3 ;
 
 /
 ?php session_start();
 include(connect.php);
 $uname=$_SESSION['username'];
 $user_balance=mysql_query($sql);
 $sql = Select  FROM users ,user_balance WHERE user_id =$uname;

you should write

$sql = Select user_balance  FROM users  WHERE user_id =$uname;

 $result = mysql_query();
 
 ?
 ?php echo $uname;?br
 ?php echo $user_balance;?
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


-- 
bala balachandar muruganantham
blog lynx http://chandar.blogspot.com
web http://www.chennaishopping.com

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



Re: [PHP] select statement

2005-05-05 Thread Prathaban Mookiah
Maybe the query should be

select user_balance FROM users WHERE user_id=$uname;

Prathap

-- Original Message ---
From: Anasta [EMAIL PROTECTED]
To: php-general@lists.php.net
Sent: Thu, 5 May 2005 16:10:35 +0800
Subject: [PHP] select statement

 Why doesnt this work, it shows the username but not the balance of 
 the users money.here is the mysql table:
 
 CREATE TABLE `users` (
   `user_id` int(11) NOT NULL auto_increment,
   `username` varchar(15) NOT NULL default '',
   `password` varchar(15) NOT NULL default '',
   `status` varchar(10) NOT NULL default '',
   `user_balance` bigint(5) NOT NULL default '0',
   PRIMARY KEY  (`user_id`)
 ) TYPE=MyISAM AUTO_INCREMENT=3 ;
 
 /
 ?php session_start();
 include(connect.php);
 $uname=$_SESSION['username'];
 $user_balance=mysql_query($sql);
 $sql = Select  FROM users ,user_balance WHERE user_id =$uname;
 $result = mysql_query();
 
 ?
 ?php echo $uname;?br
 ?php echo $user_balance;?
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
--- End of Original Message ---

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



RE: [PHP] SQL statement - please help

2005-03-24 Thread Jay Blanchard
[snip]
$sql = Select tblchatglobal.cgid, tblchatglobal.cgdateposted, 
tblchatglobal.cgtimeposted, tblchatglobal.uid, tblchatglobal.cgmsg, 
tblusers.uid, tblusers.uusername from tblchatglobal, tblusers where 
(tblchatglobal.uid = tblusers.uid) and (DATE_SUB(CURDATE(),INTERVAL 1
HOUR) 
=  tblchatglobal.cgtimeposted) order by tblchatglobal.cgtimeposted
desc;
[/snip]

One of the MySQL lists will be really helpful to you.
http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html

AND (DATE_SUB(CURDATE(),INTERVAL 1 HOUR)=  tblchatglobal.cgtimeposted)

CURDATE is wrong here, as it only returns a date. NOW() returns a
datetime. Try

AND (DATE_SUB(NOW(),INTERVAL 1 HOUR)=  tblchatglobal.cgtimeposted)

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



Re: [PHP] SQL statement - please help

2005-03-24 Thread Tom Rogers
Hi,

Thursday, March 24, 2005, 6:50:38 PM, you wrote:
J Dear all

J Please, I realy need your help.  I am trying to extract only those records
J that were entered during the past hour from my MySQL database.  The
J following SQL statement extracts all the records. As soon as I change the
J INTERVAL  to 1 HOUR I see all the records in my database. When I change
J CURDATE() to CURTIME() no records are extracted from the database. The
J cgtimeposted field is a time data type.

J Please advise me as to how I can formulate my SQL statement so that only
J those records entered within the past hour displays on my page.

J Here is my current SQL statement - this statement displays all the records:

J $sql = Select tblchatglobal.cgid, tblchatglobal.cgdateposted, 
J tblchatglobal.cgtimeposted, tblchatglobal.uid, tblchatglobal.cgmsg,
J tblusers.uid, tblusers.uusername from tblchatglobal, tblusers where
J (tblchatglobal.uid = tblusers.uid) and
J (DATE_SUB(CURDATE(),INTERVAL 1 HOUR) 
J =  tblchatglobal.cgtimeposted) order by
J tblchatglobal.cgtimeposted desc;

J Jacques 

You cannot do this with just a time field as what happens at midnight
and now() becomes 00:00:00, you will need to work with a full date_time
field.

The other problem is CURDATE has no time component, it is just a date
so subtracting 1 hour will always return 23:00:00.

So change the time field to a timestamp and try

... AND  tblchatglobal.cgtimeposted  (DATE_SUB(NOW(),INTERVAL 1 HOUR))

-- 
regards,
Tom

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



Re: [PHP] if statement probable bug

2005-03-24 Thread Richard Davey
Hello TheI2eptile,

Thursday, March 24, 2005, 2:05:14 PM, you wrote:

T So here is what I would call a bug, but maybe it's thought to be so:

Try it with strict (data-type) comparisons, i.e.:

if ($var === AS)

Then you won't get the bug.

Best regards,

Richard Davey
-- 
 http://www.launchcode.co.uk - PHP Development Services
 I do not fear computers. I fear the lack of them. - Isaac Asimov

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



Re: [PHP] if statement probable bug

2005-03-24 Thread Jochem Maas
TheI2eptile wrote:
Probably this is the wrong place to put this but I couldn't search for 
not at all the wrong place, having said that the only thing probable with 
regard
to you/your post is that you are not fully aware of the nature of data types in
php and the way auto-typecasting works (in terms of precedence and 
conversion)...
which is not surprising, most people get bitten by this at some time :-) because
often when looking at the behaviour from the point of view of other
langs (or as a complete beginner) the logic behind it may not seem at all 
logical...
I recommend searching for some more info on (auto)typecasting in php,
by the sounds of things you're capable of grokking the whys and wherefores 
without
much trouble :-)
the bug and what I saw in the bugs newsgroup was a bit strange and seem 
to be a log for the bugs forms.

So here is what I would call a bug, but maybe it's thought to be so:
?php
$var1 =  0;
$var2 = AS;
if($var1 == AS){
echo brWhy is this printed;
}
int has higher precendence... therefore AS is converted to an int
... AS when converted to an int is zero... the order of the operands does not
matter in this case, try the following one liner:
?php var_dump( (0 == AS), (AS == 0) ); ?
if(0 == AS){
echo brAt least this should not be printed;
}
same rules applies here.
if($var2 == AS){
echo brOnly this should;
}
?
I didn't expect it. I use php 5.02 and have the zend debugger installed. 
Does anybody see every echo and finds this strange in a typeless language?
php is not typeless! its dynamically typed.
I wonder if there are typeless langs at all :-)
btw: yes I see every echo, no I don't find it strange (anymore!)
as someone else already mentioned: use the strict equality operator (===) to
tell php not to do auto-typecasting on the vars you want to check for equality.
rgds,
Jochem

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


Re: [PHP] OR statement

2005-03-24 Thread Tom Rogers
Hi,

Friday, March 25, 2005, 11:27:30 AM, you wrote:
MD Hello,

MD I would like to first thank everyone for their help with the last few
MD questions I have had. I really appreciate it.

MD Here is my question:

MD  if ($audio == Cool){

MD Do this

MD }else{

MD Do that

MD }

MD This work fine, however, I would like to add to the criteria above. I would
MD like to say:

MD  if ($audio == Cool or junk or funky){

MD ...

MD I have tried to look for something in the manual, and am still looking, but
MD a little help on this would be appreciated.

MD Thank you again,

MD --
MD Steve Marquez

The most easily expandable way is with a switch statement

switch($audio){
  case 'Cool':
  case 'junk':
  case 'funky':
Do this
  break;
  default:
Do that
  break;
}

-- 
regards,
Tom

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



Re: [PHP] OR statement

2005-03-24 Thread Josh Whiting
 This work fine, however, I would like to add to the criteria above. I would
 like to say:
 
  if ($audio == Cool or junk or funky){
 
 ...
 

if (in_array($audio,array(Cool,junk,funky))) {
...
}

not the most elegant looking but it gets the job done.

/josh w

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



Re: [PHP] OR statement

2005-03-24 Thread Philip Olson
  This work fine, however, I would like to add to the criteria above. I would
  like to say:
  
   if ($audio == Cool or junk or funky){
  
  ...
  
 
 if (in_array($audio,array(Cool,junk,funky))) {
 ...
 }
 

Yes that's one way but to answer the question:

 if ($a == 'foo' OR $a == 'bar') {


Regards,
Philip

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



  1   2   3   >