Re: [PHP] Coding Question

2004-12-13 Thread Justin French
On 07/12/2004, at 6:50 AM, Al wrote:
Jason Wong wrote:
On Monday 06 December 2004 14:19, Rory Browne wrote:
If I'm not mistaken Al wanted to return something if the thing 
failed,
without having to put it inside an if_block.

I'm watching this with curiosity, because return is a language
construct, and not a function, or anything that has a value.
You can have:
  ... OR $error = Oh dear;
But the say I see it, eventually, somewhere in your code you need to 
test for it. Essentially you're just moving the test somewhere else.

Essentially, I'm creating warning reports for my users, not code 
errors.  The users can then email the warnings to our webmaster.
That's totally the wrong approach.  Dumping errors to the screen and 
asking the end user to create an email for the webmaster is just a 
fantasy.  99% of users will walk away and never return.  It's bad user 
experience, and it's a crisis point that you're handling badly.

A better plan would be to hide all the errors from the user, log them 
to and error log, automatically email the webmaster, and present a 
simple something went wrong, sorry, we're working on it to the user.

They don't need to know anything about mysql, tables, databases, etc -- 
the WEBMASTER does, but not the user.

---
Justin French, Indent.com.au
[EMAIL PROTECTED]
Web Application Development  Graphic Design
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Coding Question

2004-12-06 Thread Richard Lynch
Al wrote:
 I've searched the PHP manual and can't find an answer for this question

 I'd like to use the OR DIE construct; but instead of DIE I'd like to
 use
 RETURN FOO. I haven't found a way to do it.


 $string= file_get_contents($filename)
   OR die(Could not read file);

 $db_link= mysql_connect($host, $user, $pw)
 OR die(Could not connect:  . mysql_error());

 Seems like it would be nice to not have to test first, e.g.,
 if(is_readable($filename)){ }

You may want to use:

or http://php.net/exit
or http://php.net/return

I will not guarantee that either will work, much less do what you want,
which I don't really understand in the first place.

-- 
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] Coding Question

2004-12-06 Thread Al
Jason Wong wrote:
On Monday 06 December 2004 14:19, Rory Browne wrote:
If I'm not mistaken Al wanted to return something if the thing failed,
without having to put it inside an if_block.
I'm watching this with curiosity, because return is a language
construct, and not a function, or anything that has a value.

You can have:
  ... OR $error = Oh dear;
But the say I see it, eventually, somewhere in your code you need to test for 
it. Essentially you're just moving the test somewhere else.


Essentially, I'm creating warning reports for my users, not code errors.  The 
users can then email the warnings to our webmaster.

Here's what I ended up with:

@$host_link= mysql_connect($host, $user, $pw) 
		OR $values['msg']= $values['msg'] . Could not connect to mySQL host ;
	   
	
	if($host_link){
		$db_link= mysql_select_db($db, $host_link)
			OR $values['msg']= $values['msg'] . Could not connect to mySQL DB: $db;
	}
	
	if($host_link AND $db_link){
		$result = mysql_db_query($db,select count(*) from $table)
			OR $values['msg']= $values['msg'] . Could not connect to mySQL Table: $table;
	}
	if($host_link AND $db_link AND $result){
	
	$values['num_records'] = ($result0) ? mysql_result($result,0,0) : 0;
		
	}//end if
		
	return $values;		//tech notes and db table stuff
The calling page echoes $values['msg'] in nice red text.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Coding Question

2004-12-06 Thread Richard Lynch
Al wrote:
 Essentially, I'm creating warning reports for my users, not code errors.
  The
 users can then email the warnings to our webmaster.

 Jason Wong wrote:
 On Monday 06 December 2004 14:19, Rory Browne wrote:

  $result = mysql_db_query($db,select count(*) from $table)
  OR $values['msg']= $values['msg'] . Could not connect 
 to mySQL
 Table: $table;

//tech notes and db table stuff

 The calling page echoes $values['msg'] in nice red text.

Here's what's wrong with this plan:

#1.
You are exposing the fact that you use MySQL to users.  So malicous users
don't need to figure out that you are using MySQL: They can just start
trying all the MySQL things to break into your server.

As a general rule, you do not want users to know what software/version you
are running.

While this does fall into the security by obscurity category, which is
generally not good there are compelling arguments for making it harder
for the bad guys to figure out what software you are using.

#2.
They won't.
Oh, sorry.
The USERS will *NOT* email your message to the webmaster.  Oh, some will. 
Most, however, will email your webmaster with oh-so-usefull messages like.
I was on your website, and I got an error message, and it's broken.
HELP!

Put the details you need to debug your software in a place where you
webmaster can read them, no matter what the user does to mangle, shorten,
or otherwise ruin the message.

http://php.net/error_log is good for this.

#3.
It's just Bad Form to tell users a bunch of crap they don't understand,
don't care about, and can only be puzzled by.  The message the users see
should be more like:  Website down for maintenance.  Please try again
later.

The error messages you need to FIX the site are in the Apache log (or your
own logfile) where they belong.



There might be some exceptions to all this -- If you have only one or two
admin people, whom you trust to actually copy paste the error messages
and send them to you, displaying them on those admin screens is not so
bad.  That user is probably your client who already knows what software is
in use (or can find out easily) and isn't likely to sabotage their own
site, and can maybe be trained to do the right thing...  OTOH, logging to
a file and giving them a message they understand (Something broke.  Call
Rich and tell him what you were doing.) is probably better anyway.

-- 
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] Coding Question

2004-12-06 Thread Al
Richard Lynch wrote:
Al wrote:
Essentially, I'm creating warning reports for my users, not code errors.
  The
users can then email the warnings to our webmaster.
Jason Wong wrote:
On Monday 06 December 2004 14:19, Rory Browne wrote:
$result = mysql_db_query($db,select count(*) from $table)
OR $values['msg']= $values['msg'] . Could not connect 
to mySQL
Table: $table;

//tech notes and db table stuff
The calling page echoes $values['msg'] in nice red text.

Here's what's wrong with this plan:
#1.
You are exposing the fact that you use MySQL to users.  So malicous users
don't need to figure out that you are using MySQL: They can just start
trying all the MySQL things to break into your server.
As a general rule, you do not want users to know what software/version you
are running.
While this does fall into the security by obscurity category, which is
generally not good there are compelling arguments for making it harder
for the bad guys to figure out what software you are using.
#2.
They won't.
Oh, sorry.
The USERS will *NOT* email your message to the webmaster.  Oh, some will. 
Most, however, will email your webmaster with oh-so-usefull messages like.
I was on your website, and I got an error message, and it's broken.
HELP!

Put the details you need to debug your software in a place where you
webmaster can read them, no matter what the user does to mangle, shorten,
or otherwise ruin the message.
http://php.net/error_log is good for this.
#3.
It's just Bad Form to tell users a bunch of crap they don't understand,
don't care about, and can only be puzzled by.  The message the users see
should be more like:  Website down for maintenance.  Please try again
later.
The error messages you need to FIX the site are in the Apache log (or your
own logfile) where they belong.

There might be some exceptions to all this -- If you have only one or two
admin people, whom you trust to actually copy paste the error messages
and send them to you, displaying them on those admin screens is not so
bad.  That user is probably your client who already knows what software is
in use (or can find out easily) and isn't likely to sabotage their own
site, and can maybe be trained to do the right thing...  OTOH, logging to
a file and giving them a message they understand (Something broke.  Call
Rich and tell him what you were doing.) is probably better anyway.
I greatly appreciate your taking an interest in my question.
I didn't explain all the details since I was trying to keep my message short.
My users are not public.  They are a few selected individuals who only have 
access via an Apache authentication dialog.

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


Re: [PHP] Coding Question

2004-12-05 Thread Ligaya Turmelle
snip
 $db_link= mysql_connect($host, $user, $pw)
OR die(Could not connect:  . mysql_error());
/snip
try:
$db_link= mysql_connect($host, $user, $pw);
if (!$db_link){
   // do whatever if there is something wrong
}
maybe try something like that with the file_get_contents also?
Respectfully,
Ligaya Turmelle
---
Life is a game... so have fun.
---
www.PHPCommunity.org
Open Source, Open Community
Visit for more information or to join the movement

Al wrote:
I've searched the PHP manual and can't find an answer for this question
I'd like to use the OR DIE construct; but instead of DIE I'd like to 
use RETURN FOO. I haven't found a way to do it.

$string= file_get_contents($filename)
OR die(Could not read file);
$db_link= mysql_connect($host, $user, $pw)
   OR die(Could not connect:  . mysql_error());
Seems like it would be nice to not have to test first, e.g., 
if(is_readable($filename)){ }

Thanks

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

Re: [PHP] Coding Question

2004-12-05 Thread Rory Browne
If I'm not mistaken Al wanted to return something if the thing failed,
without having to put it inside an if_block.

I'm watching this with curiosity, because return is a language
construct, and not a function, or anything that has a value.

I could probably have said that better sober, and not at 06:16am, but
hopefully  you get my drift.

On Mon, 06 Dec 2004 09:11:26 +1000, Ligaya Turmelle [EMAIL PROTECTED] wrote:
 snip
   $db_link= mysql_connect($host, $user, $pw)
  OR die(Could not connect:  . mysql_error());
 /snip
 
 try:
 $db_link= mysql_connect($host, $user, $pw);
 if (!$db_link){
 // do whatever if there is something wrong
 }
 
 maybe try something like that with the file_get_contents also?
 
 Respectfully,
 Ligaya Turmelle
 
 ---
 Life is a game... so have fun.
 ---
 www.PHPCommunity.org
 Open Source, Open Community
 Visit for more information or to join the movement
 
 
 
 
 Al wrote:
  I've searched the PHP manual and can't find an answer for this question
 
  I'd like to use the OR DIE construct; but instead of DIE I'd like to
  use RETURN FOO. I haven't found a way to do it.
 
 
  $string= file_get_contents($filename)
  OR die(Could not read file);
 
  $db_link= mysql_connect($host, $user, $pw)
 OR die(Could not connect:  . mysql_error());
 
  Seems like it would be nice to not have to test first, e.g.,
  if(is_readable($filename)){ }
 
  Thanks
 
 
 
 --
 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] Coding Question

2004-12-05 Thread Jason Wong
On Monday 06 December 2004 14:19, Rory Browne wrote:
 If I'm not mistaken Al wanted to return something if the thing failed,
 without having to put it inside an if_block.

 I'm watching this with curiosity, because return is a language
 construct, and not a function, or anything that has a value.

You can have:

  ... OR $error = Oh dear;

But the say I see it, eventually, somewhere in your code you need to test for 
it. Essentially you're just moving the test somewhere else.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
There's a whole WORLD in a mud puddle!
  -- Doug Clifford
*/

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



Re: [PHP] Coding Question

2003-07-20 Thread Justin French
Retrieving the results can be LIMITed to X results starting at row Y 
using mysql's LIMIT function.

Check the MySQL manual, but basically, this will limit the result to 10 
rows, starting with row 5.

SELECT name FROM customers LIMIT 5,10

By taking your values for the starting point and row count from 
variables from within the url, a posted form, session, cookie, etc, you 
can build dynamic queries, eg:

$sql = SELECT name FROM customers LIMIT {$start},{$perPage};

You can also build next and previous links by adding and subtracting 
the $perPage to the $start.

Make sense?

There's plenty of tutorials -- just do a google search.

Justin



On Sunday, July 20, 2003, at 05:55  PM, Aaron Axelsen wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hello,

I am currently trying to think of how I want to solve an issue, and
im looking for some input.
I have a page that will query information from a database and then
properly display it on the screen.  Now the thing I want to set up is
the option to split the information over 2,3 or more pages.
For example, the user can set a value in the config file for how many
results to display for page, then on each page ill have something
that says results 25-50 here and what not.
The only thing that comes to my mind, is somehow setting up some
tests, and then altering the sql statement with the list option.  Is
this the best way to do this?  Does anyone else have any other
suggestions??
Thanks in advance for the assistance.

- ---
Aaron Axelsen
AIM: AAAK2
Email: [EMAIL PROTECTED]
Want reliable web hosting at affordable prices?
www.modevia.com
Web Dev/Design Community/Zine
www.developercube.com
-BEGIN PGP SIGNATURE-
Version: PGPfreeware 7.0.3 for non-commercial use http://www.pgp.com
iQA/AwUBPxpK1brnDjSLw9ADEQK0cQCgmFLBwO/IeqIYZIJUhR2j23Na5/sAniYv
nXehy/vKSs6AE8/yI3O9BixJ
=s7G2
-END PGP SIGNATURE-


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
---
[This E-mail scanned for viruses]



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