HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


why is variable undefined?

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#78079 (In Topic #16021)
Avatar

Community saint

Added this little bit, and more, to some already existing code:

Code (php)

[semihtml]<br />
$image_data=$GLOBALS[&#39;SITE_DB&#39;]-&gt;query(&#39;SELECT * FROM &#39;.get_table_prefix().&#39;images ORDER BY add_date DESC LIMIT 10&#39;);<br />
<br />
foreach ($image_data as $row)<br />
{<br />[/semihtml]


This code, gets an error and I get stack trace.   not sure why 'row' is 'undefined' ...   ?????

An error has occurred

PHP NOTICE [8] Undefined variable: row in site/pages/modules_custom/galleries.php on line 1336 (version: 7.1.5, PHP version: 5.2.17, URL: /mgalleries/index.php?page=start&type=recent)

Here is the stack trace:

Below is a stack trace revealing the state the software was in when the error occurred. If this represents a bug in the unmodified software, you may want to check Air-RC website for a fix, and if there isn't one, report this as a bug. Please note that merely posting a stack trace is not sufficient for us to solve your problem; the stack trace is just an aid that presents us with additional information. We still need to know the error message, what you tried to do, how you tried to do it, version numbers, and any other appropriate information.
We apologise for this problem and if it's a bug we hope you will work with us so that we can fix it for you promptly.

File'/home1/paulsfly/public_html/pfm/sources/failure.php'
Line'674'
Function'get_html_trace'
Args 

File'/home1/paulsfly/public_html/pfm/sources/global2.php'
Line'969'
Function'_fatal_exit'
Args'PHP NOTICE [8] Undefined variable: row in site/pages/modules_custom/galleries.php on line 1336'


File'/home1/paulsfly/public_html/pfm/sources/failure.php'
Line'214'
Function'fatal_exit'
Args'PHP NOTICE [8] Undefined variable: row in site/pages/modules_custom/galleries.php on line 1336'


File'/home1/paulsfly/public_html/pfm/sources/global2.php'
Line'843'
Function'_ocportal_error_handler'
Args'notice'

8

'Undefined variable: row'

'site/pages/modules_custom/galleries.php'

1336


File'/home1/paulsfly/public_html/pfm/site/pages/modules_custom/galleries.php'
Line'1,336'
Function'ocportal_error_handler'
Args8

'Undefined variable: row'

'/home1/paulsfly/public_html/pfm/site/pages/modules_custom/galleries.php'

1336

array ( )


File'/home1/paulsfly/public_html/pfm/site/pages/modules_custom/galleries.php'
Line'423'
Function'show_recent_images'
Class'Module_galleries'
Type'->'
ObjectModule_galleries::__set_state(array( ))
Args 

File'/home1/paulsfly/public_html/pfm/sources/zones.php'
Line'386'
Function'run'
Class'Module_galleries'
Type'->'
ObjectModule_galleries::__set_state(array( ))
Args 

File'/home1/paulsfly/public_html/pfm/sources/site.php'
Line'966'
Function'load_module_page'
Args'site/pages/modules_custom/galleries.php'

'galleries'


File'/home1/paulsfly/public_html/pfm/sources/site.php'
Line'1,038'
Function'request_page'
Args'galleries'

true

''

NULL

false

true


File'/home1/paulsfly/public_html/pfm/sources/site.php'
Line'753'
Function'request_page'
Args'start'

true


File'/home1/paulsfly/public_html/pfm/mgalleries/index.php'
Line'114'
Function'do_site'
Args 



Paul
Back to the top
 
Posted
Rating:
#78088
Avatar

The code looks fine. I suspect you're not quite seeing the code right… the error probably isn't happening inside that foreach loop. Maybe the braces aren't indented clearly, for example (can't say without seeing full code).


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#78091
Avatar

Community saint

To explain better, I added a function, that function has the above code.   

If I remove the foreach loop, the code runs without the stack trace.  It just comes up saying the function did not output any data, which is good.

If the foreach loop is empty, it get's a stack trace like above.   If the foreach has code, same stack trace.

I thought maybe sql is not returning anything, but I go into myphpadmin and run the sql and it works fine.   

So just adding that foreach line is causing this stack trace to occur.


Paul
Back to the top
 
Posted
Rating:
#78093
Avatar

My above post still holds, it still sounds like you are referencing $row after the loop finishes, but I can't say without seeing the full function.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#78095
Avatar

Community saint

Attachment
» Download: galleries.php (69 Kb, 87 downloads so far)


I have attached that file.  I do not see a reference to $row outside of that loop.

Paul
Back to the top
 
Posted
Rating:
#78097
Avatar

I didn't get that error with your code, but I got "undefined variable $content", which was solved by putting $content=new ocp_tempcode(); before the loop (to initialise $content before further Tempcode was attached)..


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#78098
Avatar

Tested with and without and images on my test site.

But of course it didn't run because I hadn't your templates.

I guess maybe you fixed your $row bug, refreshed, saw "the error" was still there, but didn't realise it was now a different variable being referred to.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#78099
Avatar

Community saint

No, I refeshed all caches.   I added the $content line like you did.   uploaded it all.  Still same exact error:

An error has occurred

PHP NOTICE [8] Undefined variable: row in site/pages/modules_custom/galleries.php on line 1336 (version: 7.1.5, PHP version: 5.2.17, URL: /mgalleries/index.php?page=start&type=recent)

Paul
Back to the top
 
Posted
Rating:
#78100
Avatar

What's line 1336 for you? When I opened the attached file, the line numbers were all skewed, most but not all were double spaced (probably a problem converting from a Windows file).


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#78101
Avatar

One unlikely, but possible, thing is if you have an opcode cache (e.g. APC, or Zend Optimizer) that is caching an old version of the PHP file. It can happen if you have a different timezone set on the server compared to where you are developing. I've hardly ever seen this happen though.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#78103
Avatar

Community saint

that line # is nowhere near my code.   But I just put a * down by the query in my function, and when it gets and error for having the * in there, it indicates the same line #.

No opcode cache running, that I know of.

Paul
Back to the top
 
Posted
Rating:
#78105
Avatar

Actually I bet you're uploading to a server with FTP resume enabled, and you're "resuming" your upload instead of doing a full re-upload.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#78107
Avatar

Community saint

not sure what that means.  I used filezilla.  Removed the file from the server and sent the new one.

Paul
Back to the top
 
Posted
Rating:
#78108
Avatar

Hmm. This is really bizarre if even that isn't it. A common mistake is to edit a file locally then upload on top of what was there before, and tell the FTP program to resume the upload, which leads to a corrupt file because the 'resumption' is between two different file versions.

I don't know what else it could be, but for your own check, I would download the file from the server and compare it to what you have locally.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#78120
Avatar

Community saint

Thanks for the suggestion.  I deleted the local one and downloaded the remote version.   The formatting was all crazy.  It had tabs instead of LF's  in some places, so some lines were 'brought up'  to comment lines that started with //  so they were seen as comments.

Crazyness.  Never seen that sort of thing happen before.   

Now I have the base part running, now a matter of formatting it all out to the templates for a good display.

Thanks for all your time looking at this.

Paul
Back to the top
 
Posted
Rating:
#78122
Avatar

Maybe you need to upload in binary mode in the FTP program?


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#78136
Avatar

Community saint

I changed it to binary.  Seems to be working fine.

Now off to figure out how to make that little action bar appear on the bottom of my new screen like it does on the main gallery screen.  Took a shot at it earlier with no luck.  Back into the code I go.

Paul
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: