Solved

php function

Posted on 2014-12-12
17
135 Views
Last Modified: 2014-12-12
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
0
Comment
Question by:Richard Korts
  • 7
  • 6
  • 3
  • +1
17 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40497160
The clue would be in the error message
Add to the top of the page

    error_reporting(E_ALL);
0
 

Author Comment

by:Richard Korts
ID: 40497164
Gary,

To the top of the function or to the top of the page in which the function is being included?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40497172
The top of the page right after your very first opening
<?php
0
 

Author Comment

by:Richard Korts
ID: 40497175
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
 

Author Comment

by:Richard Korts
ID: 40497186
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
 
LVL 58

Expert Comment

by:Gary
ID: 40497189
Are you using register_globals?
Where are all these variables coming from addr,fhour etc?
0
 

Author Comment

by:Richard Korts
ID: 40497195
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
 

Author Comment

by:Richard Korts
ID: 40497196
I am not using register globals.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 58

Expert Comment

by:Gary
ID: 40497221
You are referencing the variables in wo_updt.php before they are set then.
0
 

Author Comment

by:Richard Korts
ID: 40497262
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
 
LVL 58

Accepted Solution

by:
Gary earned 350 total points
ID: 40497266
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
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40497271
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
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 150 total points
ID: 40497284
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
 

Author Comment

by:Richard Korts
ID: 40497315
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40497435
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
 
LVL 58

Expert Comment

by:Gary
ID: 40497443
so I'll award you the points.
I'd rather have beer!
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40497471
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now