How to deal with pass a value twice in a PHP file - php

I am working on modification of a program. There are two value passes happened in one PHP file, and I get a notification from system like this:
Notice: Undefined index: content in /Users/alexhu/NetBeansProjects/menagerie/svn/trunk/apps/frontend/modules/legacy/legacy_lib/content/utilities/hraprint.php on line 23
And
Notice: Undefined index: isProvena in /Users/alexhu/NetBeansProjects/menagerie/svn/trunk/apps/frontend/modules/legacy/legacy_lib/content/utilities/hraprint.php on line 24
How to avoid it?

That error means you've basically got something like:
$my_arrray = array();
if ($my_array['content'] == ....) {
}
... attempting to access an index/key in an array which has not yet been defined. To guard against it, you'd need something like:
if (isset($my_array['content']) && ($my_array['content'] == ....)) {

Well you are trying to use an index of an array which doesn't exist.
The error is stating what is wrong :-)

You're simply trying to access $array['content'] and $array['isProvena'] in your code. Without the code we can't tell you anything though.

Related

PHP variable passing

I'm working with drupal. I have this page something.com/node/13. Inside I have this script
<?php
$door = $_GET["variable"];
echo $door;
?>
When I open the URL like this something.com/node/13?variable=1231 I get the following error:
Error message
Notice: Undefined index: variable in eval() (line 2 of /var/www/html/modules/php/php.module(74) : eval()'d code).
and no output. Any ideas what I might be doing wrong?
The error, partcilarly in drupal 7 simply means that you aren't getting any value for $_GET['variable']. This would be because the url doesn't have a value (someurl?variable=foo). You can avoid the notice by prefixing an # like this:
$door = #$_GET['variable'];
but that won't make the variable return any data. It's pretty unclear from the code you've posted what you're trying to accomplish. You might consider starting there. There is no reason why you can't use $_GET variables in drupal. I do so all the time.
Use drupal_get_query_parameters
Because the rewrite rules with Drupal, you don't grab the $_GET values cleanly directly like that.

How to Fetch Smarty Variables in PHP File?

I am display a smarty variable inside a php code, this is because i would like to compare something from Smarty into a PHP file.
Example:
<?php
$ThisIsTheSmartyVariable
If ($ThisIsTheSmartyVariable == Something) {
Do Something
}
?>
This is the main idea but i dont understand it why its not working.
When i am trying to fetch all the variables its giving me this output:
Fatal error: Call to undefined function logactivity() in public_html/includes/smarty/Smarty.class.php on line 1094
Let me know.

Form not displaying PHP Log showing Undefined index

I am getting the following errors:
PHP Notice: Undefined index: Username class.form.php on line 43
PHP Notice: Undefined index: Password class.form.php on line 54
index.php code
class.form.php code
The form is showing in the source code but not the "view"
print_r is showing Form Object ( [sHTML:Form:private] =>
Thanks
To fix the last error, change:
<?php echo $sLoginMessage ?>
to
<?php echo (isset($sLoginMessage)?$sLoginMessage:null); ?>
With your other error, you're trying to access an array index that does not exist. $this->aStickyData[$sName] and the other aStickyData error is because these array indexes are not defined.
The first two errors are referring to your attempts to access Form::$aStickyData['Username'] and Form::$aStickyData['Password'] respectively.
This data is only set on form submission. You should set default data for the initial page load.
The last error is because you're defining $sLoginMessage inside the form submission and validation conditions. You should define it earlier.

receiving error undefined index on two variables

Using adLDAP.php class
receiving following error: Notice: Undefined index: memberof in /web/ee_web/include/adLDAP.php on line 762
line 762: if (is_array($groups[0]["memberof"])) {
Also receiving error: Notice: Undefined index: count in /web/ee_web/include/adLDAP.php on line 982
line 982: $entries[0]["memberof"]["count"]++;
Unsure of what I need to do to resolve these error messages, it seems that the script is working fine, but I'd like get rid of these errors.
Using: http://adldap.sourceforge.net/wiki/doku.php?id=api
You could edit the code to something along the lines of:
if(isset($groups[0]["memberof"]))
{
if (is_array($groups[0]["memberof"])){ ... }
}
And
if(isset($entries[0]["memberof"]["count"]))
{
$entries[0]["memberof"]["count"]++;
}
It will keep you from getting the errors, though it won't necessarily handle some pretty lax sanity checking by the original author of the code.
It seems like you have your error_level set to show every possible error/warning/notice, that's why you're getting it.
If the script is working fine, then it's not an error, simply a missing check the coder forgot to put in the library.
To get rid of thos messages, you have 2 options:
a) Use # before the calls you do to that library, such as
$var = #the_function(param1);
This will avoid those messages for just that line.
b) Set the error level to something like this with error_reporting():
error_reporting(E_ALL ^ E_NOTICE);
This will affect the whole script you're running.
It's up to you what to use depending on the project.

PHP: Notice when error_reporting(E_ALL)

When I try to access info that is not presented in xml like so: $someInfo = $element->blabla->cats[0]->src;
PHP shows notice like this: Notice: Trying to get property of non-object
How would I settle the matter?
Just check if the specific element is set befor accessing data:
if(isset($element->blabla->cats[0]->src)){
$someInfo = $element->blabla->cats[0]->src;
}

Categories