By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,359 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

Please use error_reporting(E_ALL)

P: n/a
Just a couple of quick comments:

In some of the CSS/DOM mailing lists I'm on, people generally
refuse to help unless the HTML and CSS will validate. You
can check these at http://validator.w3.org/check/ and
http://jigsaw.w3.org/css-validator/check/ respectively, and it will
often sort out problems you are experiencing with layout/display if
your code validates properly.

This has led me to think of things that could be done in here, to reduce
the number of "easily fixed" posts. A lot of the problems that people in
this newsgroup tend to experience would have been easier to solve
if they did these things:

- put error_reporting(E_ALL); in all your code. If you have a globally
included/required file, stick it in the start there. Most of your
problems will become easier to identify.

You will probably find that you get problems with
Notice: undefined index in ....
Fix these by doing
if (array_key_exists('myvar', $_POST))
{
// do stuff with $_POST['myvar']
}
etc

- turn register_globals OFF. Use $_POST['variablename'] rather than
$variablename for form data. Similarly use $_GET, $_FILES, $_SERVER, $_SESSION, etc.
Your code will work on more servers, with less work, and you'll have a better handle
on where the data is coming from. Probably better to avoid $HTTP_POST_VARS if you
have a sufficiently current version of PHP; if you don't, better to use
$HTTP_POST_VARS['myvar'] than $myvar

- Check the value of mysql_error() if queries fail:
if (!($result = mysql_query($sql, $connection)))
{
print "Couldn't execute the query\n<pre>$sql</pre>\nMySQL error is \n".mysql_error();
}

- If you need to make a function call that could result in an error, you can always prefix
it with @ :
if (!@move_uploaded_file($somefile, $someotherfile))
{
// clean up here
}

- Check your query result has data in it, before fetching arrays/rows from it:
either do
if (mysql_num_rows($result))
{
// do stuff
}

or

while ($row = mysql_fetch_assoc($result))
{
// do stuff
}

- If necessary, make sure you use addslashes(0 on data before putting it into an SQL query

- Escape entities in HTML code (htmlentities(), urlencode() for URL query strings, etc)

- If your form post/file upload handlers aren't working, try doing
var_dump($_POST) or var_dump($_FILES) to see what input you're getting

Also, if you get a strange or incomprehensible error message, it's often quite
productive to try searching for the "standard" part of it in google, enclosed in quotes,
e.g. http://www.google.com/search?q=%22un...sql_connect%22

Anyone else think of any more?

I'm not trying to be nasty; it's just that following some basic checks will allow
you to find your errors more quickly and easily, and you'll start writing more
robust code as a result!

Matt
Jul 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
matty:
Just a couple of quick comments:

In some of the CSS/DOM mailing lists I'm on, people generally
refuse to help unless the HTML and CSS will validate. You
can check these at http://validator.w3.org/check/ and
http://jigsaw.w3.org/css-validator/check/ respectively, and it will
often sort out problems you are experiencing with layout/display if
your code validates properly.

This has led me to think of things that could be done in here, to reduce
the number of "easily fixed" posts. A lot of the problems that people in
this newsgroup tend to experience would have been easier to solve
if they did these things:


You're probably right, problem is they don't come here until they experience
the problem, and they clearly haven't got the slighest clue about how to
use Google Groups.

But as long as someone's willing to help I guess it's ok, but I've simply
stopped answering most of these simple questions.

André Nęss
Jul 16 '05 #2

P: n/a
André Nęss wrote:


You're probably right, problem is they don't come here until they
experience the problem, and they clearly haven't got the slighest clue
about how to use Google Groups.

But as long as someone's willing to help I guess it's ok, but I've simply
stopped answering most of these simple questions.

André Nęss


Maybe we need a FAQ...
Jul 16 '05 #3

P: n/a
matty:
Maybe we need a FAQ...


We certainly do, and the topic has been discussed before, but someone simply
has to do it :/ A Wiki is maybe an even better idea as it makes it simple
for many people to cooperatively develop it.

André Nęss
Jul 16 '05 #4

P: n/a
Agelmar wrote:
matty wrote:
André Nęss wrote:


You're probably right, problem is they don't come here until they
experience the problem, and they clearly haven't got the slighest
clue about how to use Google Groups.

But as long as someone's willing to help I guess it's ok, but I've
simply stopped answering most of these simple questions.

André Nęss


Maybe we need a FAQ...


Matty, it's the same problem. People who are asking FAQ-type questions
(e.g. register_globals questions, mysql insert / update questions, etc.)
typically do not read the group before posting and/or look for the answer
anywhere else.


Well, I'll put my site back up in a week or two - if anyone has any other
suggestions for a FAQ, stick em in here (or email them to me) and I'll put
them in!

Jul 16 '05 #5

P: n/a
André Nęss wrote:
matty:
Maybe we need a FAQ...


We certainly do, and the topic has been discussed before, but someone
simply has to do it :/ A Wiki is maybe an even better idea as it makes it
simple for many people to cooperatively develop it.

André Nęss

Don't know if I'd be prepared to do a Wiki - too many wiki terrorists around.
Maybe something with a confirmed email registration - I'll have a think. In
general, what would people want to see, beyond standard faq/wiki stuff?
Jul 16 '05 #6

P: n/a
Hi Matty!
On Mon, 11 Aug 2003 01:33:57 +0000, matty
<ma*******@askmenoquestions.co.uk> wrote:
André Nęss wrote:
matty:
Maybe we need a FAQ...


We certainly do, and the topic has been discussed before, but someone
simply has to do it :/ A Wiki is maybe an even better idea as it makes it
simple for many people to cooperatively develop it.

André Nęss

Don't know if I'd be prepared to do a Wiki - too many wiki terrorists around.
Maybe something with a confirmed email registration - I'll have a think. In
general, what would people want to see, beyond standard faq/wiki stuff?


I think a FAQ would be more than enough. The FAQ of de.comp.lang.php.*
is fabolous and contains not much more than FAQ.

Jochen

--
Jochen Daum - CANS Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.