FutureQuest, Inc. FutureQuest, Inc. FutureQuest, Inc.

FutureQuest, Inc.
Go Back   FutureQuest Community > General Site Owner Support (All may read/respond) > PHP, Perl, Python and/or MySQL
User Name
Password  Lost PW

Reply
 
Thread Tools Search this Thread Display Modes
Old 10-09-2019, 02:35 PM   Postid: 187387
chernove
Site Owner
 
chernove's Avatar

Forum Notability:
65 pts: Helpful Contributor
[Post Feedback]
 
Join Date: Jan 2002
Location: NYC
Posts: 162
Use of undefined constant

Dear all,

I have (finally) updated the PHP version on my site, but I've got loads of old scripts, so I'm working to update them one at a time.

Most of the changes, of course, are updating from mysql codes to mysqli.

The first one I'm working on runs a cron job to hit one of my databases, grab info, and then send an email with the info to folks whose email addresses are on a list from another database.

While testing, I've temporarily updated the cron to run every minute and I've removed all users' email addresses except my own.

I updated the code and it actually works perfectly; in other words, I am getting the email (subject "Musicians of the Day"), formatted correctly with the correct information.

However, I am also getting a Cron Daemon email (more specifics on this in a moment.....)

The relevant part of the code is here (if you need more context, let me know, please):

PHP Code:
while($row mysqli_fetch_assoc($eprep)) {

$email $row[email];

mb_language("uni");
$message1 mb_convert_encoding($message1"UTF-8");
$message2 mb_convert_encoding($message2"UTF-8");
$message3 mb_convert_encoding($message3"UTF-8");
  
mb_send_mail ("$email","Musicians of the Day","$messagestart $message1 $message2 $message3 $messagestop","$headers");
};
?> 
The issue is with line 145, which is:
$email = $row[email];

If I leave it as is, the Cron Daemon says that it's a "Use of undefined constant email - assumed 'email' (this will throw an Error in a future version of PHP)"

My initial thought was that I needed the quote marks now:

$email = $row['email'];

which still gets me a Cron Daemon email, but one which is literally blank.

I imagine this is a really simple thing to fix, but I'm currently stumped. Have tried many things, none of which are worth going over here.

Thoughts?
chernove is offline   Reply With Quote
Old 10-09-2019, 03:52 PM   Postid: 187388
 Kevin
Systems Administrator
 
Kevin's Avatar
 
Join Date: Aug 2001
Location: Orlando, FL
Posts: 2,986
Re: Use of undefined constant

You are correct that the quotes are needed.

As far as the empty email goes, cron will email any output that it gets OR it will email if it gets an exit code other than 0. So, it may simply be that your script is producing some output (maybe just a newline) that cron is emailing you.
__________________
Kevin
Kevin is offline   Reply With Quote
Old 10-10-2019, 09:23 AM   Postid: 187392
chernove
Site Owner
 
chernove's Avatar

Forum Notability:
65 pts: Helpful Contributor
[Post Feedback]
 
Join Date: Jan 2002
Location: NYC
Posts: 162
Re: Use of undefined constant

Thank you, Kevin. Still running into the issue, which is weird.
The "real" email is coming correctly based on the headers I have in the php script. The blank email is, in fact, a Cron Daemon email. I've scoured the php file for errors (including newlines), and I even double-checked the crontab itself. Both look kosher to me. Very strange. Would it help to post the complete PHP file (editing out sensitive info, of course)?
chernove is offline   Reply With Quote
Old 10-10-2019, 09:55 AM   Postid: 187393
 Kevin
Systems Administrator
 
Kevin's Avatar
 
Join Date: Aug 2001
Location: Orlando, FL
Posts: 2,986
Re: Use of undefined constant

I was able to find the script in your account (3 versions of it). I don't see why it would be making output but it must be.

I didn't want to try running it manually since it emails but you can try running it manually at the shell prompt. You can also try running it like:
Code:
/usr/bin/php -q scriptfile |& hexdump -c
which would allow you to see any whites pace characters it prints.
__________________
Kevin
Kevin is offline   Reply With Quote
Old 10-10-2019, 11:41 AM   Postid: 187394
chernove
Site Owner
 
chernove's Avatar

Forum Notability:
65 pts: Helpful Contributor
[Post Feedback]
 
Join Date: Jan 2002
Location: NYC
Posts: 162
Re: Use of undefined constant

Ran it on PuTTY with
Code:
/usr/bin/php -q scriptfile |& hexdump -c
(a few times, actually).
Each time, "real" email got sent, with no Cron Daemon blank email. Prompt returned:

0000000
0000001

(had blank line after 0000001).

Additional thoughts?
chernove is offline   Reply With Quote
Old 10-10-2019, 11:51 AM   Postid: 187395
 Kevin
Systems Administrator
 
Kevin's Avatar
 
Join Date: Aug 2001
Location: Orlando, FL
Posts: 2,986
Re: Use of undefined constant

That is saying it is outputting a single space without a newline. I sure don't see why it would do that looking at the code but it is somehow.

It wouldn't send a cron email since you aren't running it through cron.
__________________
Kevin
Kevin is offline   Reply With Quote
Old 10-10-2019, 10:56 PM   Postid: 187396
chernove
Site Owner
 
chernove's Avatar

Forum Notability:
65 pts: Helpful Contributor
[Post Feedback]
 
Join Date: Jan 2002
Location: NYC
Posts: 162
Re: Use of undefined constant

Thanks, Kevin. Yes, it is an oddity.

Quote:
Originally Posted by Kevin View Post
It wouldn't send a cron email since you aren't running it through cron.
Yes, I know, of course. I included my comment on it just to be a completest covering all the variables I discussed earlier.

Hmmmmm....maybe after I make all the other coding updates I have to make and do the final version update (I am one removed right now because the latest is crashing far too many of my scripts), it'll get fixed. It's not the most urgent thing right now, so I'll deal with it later. To be continued.....

(And, of course, I'll keep you up to date if anything changes/gets resolved).
chernove is offline   Reply With Quote
Old 10-13-2019, 07:17 PM   Postid: 187402
chernove
Site Owner
 
chernove's Avatar

Forum Notability:
65 pts: Helpful Contributor
[Post Feedback]
 
Join Date: Jan 2002
Location: NYC
Posts: 162
Re: Use of undefined constant

Found the extra space, the sneaky little thing! (Was in one of the required imported codes). All good at the moment. The adventures continue....
chernove is offline   Reply With Quote
Old 10-13-2019, 09:30 PM   Postid: 187403
 Kevin
Systems Administrator
 
Kevin's Avatar
 
Join Date: Aug 2001
Location: Orlando, FL
Posts: 2,986
Re: Use of undefined constant

I am glad you found your stray space.

I should have mentioned this before but if you have a cron job that makes output you don't care about you can dump the output by adding >/dev/null after the command. Error messages are *SUPPOSED* to be sent to stderr instead of stdout so you should still get an email if there is an actual error but there is the occasional exception.
__________________
Kevin
Kevin is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 visitors)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 12:25 AM.


Running on vBulletin®
Copyright © 2000 - 2019, Jelsoft Enterprises Ltd.
Hosted & Administrated by FutureQuest, Inc.
Images & content copyright © 1998-2019 FutureQuest, Inc.
FutureQuest, Inc.