php function

I have the attached php function. It is included in several programs using
include "parts_dols.php";

In one specific case, I put the include in at the top of the file, like this:

<?php
include "labor_dols.php";
include "parts_dols.php";

When I do this, the program fails, even when I do not execute the function in the program.

I use the function successfully in 4 - 5 other programs.

What can cause this?

Thanks
parts-dols.php
Richard KortsAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
GaryConnect With a Mentor Commented:
Just to be clear - it's when you include parts_dols.php that the page fails?

Are you sure that function
function parts_dols

is not already being included somewhere else?

I don't see how that page can cause all the other errors.
0
 
GaryCommented:
The clue would be in the error message
Add to the top of the page

    error_reporting(E_ALL);
0
 
Richard KortsAuthor Commented:
Gary,

To the top of the function or to the top of the page in which the function is being included?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
GaryCommented:
The top of the page right after your very first opening
<?php
0
 
Richard KortsAuthor Commented:
Gary,

I put it in the referencing program (NOT the function).

I get a LOT of these:

Notice: Undefined index: addr in /home/fwsprinkler/public_html/fwsprinklercdb.info/wo_updt.php on line 67

Notice: Undefined index: invp in /home/fwsprinkler/public_html/fwsprinklercdb.info/wo_updt.php on line 76

Notice: Undefined index: wop in /home/fwsprinkler/public_html/fwsprinklercdb.info/wo_updt.php on line 81

Notice: Undefined index: warr in /home/fwsprinkler/public_html/fwsprinklercdb.info/wo_updt.php on line 86

Notice: Undefined index: lg1 in /home/fwsprinkler/public_html/fwsprinklercdb.info/wo_updt.php on line 92

Notice: Undefined index: lg2 in /home/fwsprinkler/public_html/fwsprinklercdb.info/wo_updt.php on line 95

Notice: Undefined index: fhour in /home/fwsprinkler/public_html/fwsprinklercdb.info/wo_updt.php on line 99

Notice: Undefined index: tax in /home/fwsprinkler/public_html/fwsprinklercdb.info/wo_updt.php on line 104

Notice: Undefined index: emfee in /home/fwsprinkler/public_html/fwsprinklercdb.info/wo_updt.php on line 106

Notice: Undefined index: locf in /home/fwsprinkler/public_html/fwsprinklercdb.info/wo_updt.php on line 110

Notice: Undefined index: ckd2014-12-040rkorts1 in /home/fwsprinkler/public_html/fwsprinklercdb.info/wo_updt.php on line 159
0
 
Richard KortsAuthor Commented:
The top looks like this now:

<?php
session_start();
error_reporting(E_ALL);
include "parts_dols.php";
include "labor_dols.php";      

I had session_start() farther down, it complained about "headers already sent" so I moved it to the top.
0
 
GaryCommented:
Are you using register_globals?
Where are all these variables coming from addr,fhour etc?
0
 
Richard KortsAuthor Commented:
Statements like these:

$addr = conv_quotes($_REQUEST['addr']);
$wonotes = conv_quotes($_REQUEST['notes']);

addr, etc. are on the HTML form being submitted with POST method.
0
 
Richard KortsAuthor Commented:
I am not using register globals.
0
 
GaryCommented:
You are referencing the variables in wo_updt.php before they are set then.
0
 
Richard KortsAuthor Commented:
Gary,

The program wo_updt.php works PERFECTLY if I don't put that include in.

The include causes it to fail without the included function being referenced.

The SAME include is used in 4 - 5 other programs & works flawlessly.

It makes NO sense.

So I guess I gust have to copy the code in the included function & use it directly in the program; don't like to do that because now it's in two places.
0
 
Dave BaldwinFixer of ProblemsCommented:
In order to avoid errors like that, I use a little more complicated method of getting my POST variables.  If the variable does not exist, then I create a blank variable.  This also avoids the problem of "Undefined index" errors.  If it does exist, I assign the POST value to the regular variable after limiting it's length.  That limits the amount of garbage people can post in the forms.

if (!isset($_POST["Name"]))  $Name = ''; else $Name = substr($_POST["Name"],0,64);

Open in new window

With all the typing that is required, programming seems to be specialized secretarial work at times.
0
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
I just looked at 'parts_dols.php'.  It can NOT cause the errors you listed above.  It is just a database function.  About the only line that could cause a problem is the 'include'.  Putting that code in the 'main' program will not help any.

And frankly, you have not yet given us the error message that you get when you include 'parts_dols.php'.
0
 
Richard KortsAuthor Commented:
I put that code in the main program, it works perfectly.

FYI, the error became apparent because the program (as the name suggests) is supposed to update a Work Order with any changes specified on the referencing page, then redirect back to that page.

I noticed the failure because it never redirected back, I put in a bunch of echos, it goes ALL the way to the end.

It's nuts.

But you are both good guys & eager to help & it's Christmas, so I'll award you the points.
0
 
Ray PaseurCommented:
if (!isset($_POST["Name"]))  $Name = ''; else $Name = substr($_POST["Name"],0,64);

Open in new window

is sometimes written with a ternary operator like this:
$Name 
= !empty($_POST["Name"])
? substr($_POST["Name"],0,64)
: NULL
;

Open in new window

Other filtering functions are sometimes used.  Explore PHP filter_var() for more.
0
 
GaryCommented:
so I'll award you the points.
I'd rather have beer!
0
 
Dave BaldwinFixer of ProblemsCommented:
I've seen that format before.  I've been using my version for years now.  I create so many forms that I have a PHP program that generates that for all the POST values from a form so I can just copy and paste it into the actual PHP page that will receive the form data.  It saves a Lot of typing (and error correcting!).  Here it is, I call it 'postgen.php'.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>POST Gen</title>
</head>
<body>
<pre>
<?php 
//var_dump($_POST);
foreach($_POST as $key => $value) {
    echo 'if (!isset($_POST["'.$key.'"]))  $'.$key.' = \'\'; else $'.$key.' = substr($_POST["'.$key.'"],0,64);'."<br>";
}

?>
</pre>
</body>
</html>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.