Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variables doesn't works

Status
Not open for further replies.

egmweb

Programmer
Mar 19, 2004
147
EU
Hello all.

I'm making a website based on php/mysql and I have some functions which I include in index.php at begin of this file.

But I have a problem with the variables... when I send a variable through get method to the next .php page, it displaay the following errors:

Notice: Undefined variable: error in C:\Apache2\htdocs\pcplus\index.php on line 257

thanks you.
 
egarc1a said:
Notice: Undefined variable: error in C:\Apache2\htdocs\pcplus\index.php on line 257

It's telling you That the variable [red]error[/red] is not defined where you are using it. The variable is called "error"

I'd recommend checking where the variable is coming from.

And why it is not set where you are trying to use it in thhe line from the warning.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks you,

At the url I'm sending index.php?error=1

And I have in the first line of my code:

$error = $_GET["error"];

Do you speak spanish?

Thanks you.
 
The website was working, but somebody change something at php.ini...

Since this change the website doesn't works

 
Yes, I do speak spanish. hower the site wont allow to posy in spanish it will delete the posts.

I'll place it as a quote and see if it works:

Espanol said:
Parece que cambiaron el GET en el php.ini, tienes que pedir que te lo habiliten. Sino no vas a poder pasar variables.
que pasa si tratas de llamar a tu variable error con:
[green]$_REQUEST['error'][/green]? que pasa? La otra es que vuelvan a habilitar las Variables GET en php.ini La directiva variable_order creo que es la que hay que cambiar.
It looks like they changed the GET method in the php.ini file. You have to change it back to allow Get variables.
Something with the variables_order directive in the PHP ini.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hello vacunita.

Thanks you very much.

I have all access to php.ini, so I can modify anything you suggest me, because I'm not on production environment.

The variable works with $_REQUEST... Almost all variables in the code are globals, but I saw in some papers that the request_globals should be off by security reasons. Therefore Please I need to solve this issue. how can activate the GET again??? to change every function to be a normal variables instead globals??

Thanks you.

Eduard
 
Just so we are clear, $_GET is also a global variable.

Anyway, you have to go ino the php.ini and change a directive dependng on your version of PHP.
Si tienes la version 4.0 o anterior tienes que cambiar variables_order. para que diga variables_order="EGPCS"

Si tienes la version arriba de 4.0 entonces es gpc_orders="EGPCS"

Once it is changed save the file, it should take effect immediately.





----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
To be most exact, $_POST, $_GET, etc aren't just global variables. They are defined as superglobal variables.

The real problem with using $_REQUEST is that doing so make you vulnerable to exactly the same variable-poisoning security issues that you are by having register_globals set to "on":
Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Just as a note:
vacunita said:
And why it is not set where you are trying to use it in thhe line from the warning.

This actually is not a Warning, it is merely a notice. What has changed in the PHP.ini is probably the level of error reporting. Remember that the level of error reporting can be set at run-time, so no change in the php.ini is required.
It is a notice only and probably used to be suppressed.

Of course, I'm joining the choir with sleipnir about the variable poisoning possible with $_REQUEST. It is also to be pointed out that uninitialized variables should not exist (hence the notice).
 
Thanks you all.

This is the fact. I have an index.php with an include to call differents .php files which has differents functions, for example:

In my index.php I have:
include("functions.php");

Inside the functions.php I have:
Include_once("worklist.php"); ..... etc.

When I start the index.php on apache (localhost)... The variables which I'm returning from functions.php and inside that, worklist.php, are not working... and the message are:
Notice: Undefined variable: and
Notice: Undefined index:

And the website doesn't show me anything of the database.

I thinks this could be a configuration on the php.ini, because I' have tested another website locally which worked before perfectly and It doesn't work right now either. Same is with this website.

I already reinstall php, but nothing.

thanks you
 
ok. here it is.
index.php:
<?
session_start();
include ("store_sc_fns.php");
.... etc

$name = get_category_name($catid);

do_html_header($name);

$items_array = get_items($catid);

display_items($items_array);

function do_html_header($title = '')
{
if(!$items) $items = "0";
if(!$total_price) $total_price = "0.00";
?>

?>
store_sc_fns.php
<?
include_once("db_fns.php");
include_once("output_fns.php");
include_once("store_fns.php");
include_once("order_fns.php");
include_once("vars.php");
?>
Inside each php file of store_sc_fnc.php, I have all functions, for example:

function get_category_name($catid)// inside store_fns.php
{
$conn = db_connect(); // inside db_fns.php
$query = "select catname
from categories
where catid = $catid";
$result = @mysql_query($query);
if (!$result)
return false;
$num_cats = @mysql_num_rows($result);
if ($num_cats ==0)
return false;
$result = mysql_result($result, 0, "catname");
return $result;
}

function get_items($catid) // inside output_fns.php
{
// petición a la base de datos de los libros de una categoría
if (!$catid || $catid=="")
return false;

$conn = db_connect();
$query = "select * from items where catid='$catid'";
$result = @mysql_query($query);
if (!$result)
return false;
$num_items = @mysql_num_rows($result);
if ($num_items ==0)
return false;
$result = db_result_to_array($result);
return $result;
}
...and...
function display_items($items_array)// inside output_fns.php
{
//display all items in the array passed in
if (!is_array($items_array))
{
echo "<br>No Items en esta categoria<br>";
}
else
{
//create table
echo "<table width = \"100%\" border = 0>";

//create a table row for each book
foreach ($items_array as $row)
{
$url = "show_item.php?pid=".($row["pid"]);
echo "<tr><td class=\"table1\">";
if (@file_exists("images/".$row["pid"]."s.jpg"))
{
$title = "<img src=\"images/".($row["pid"])."s.jpg\" border=0>";
do_html_url($url, $title);
}
else
{
echo "&nbsp;";
}
echo "</td><td class=\"table1\" align=\"left\" valign=\"middle\">";
$title = $row["title"]." by ".$row["marca"];
do_html_url($url, $title);
echo "</td></tr>";

}
echo "</table>";
}

}

Here is part of the code. please help me whith this... before was working and now anything work.

Thanks you.

Eduard
 
ok. here are the messages:

Notice: Undefined variable: catid in C:\Apache2\htdocs\pcplus\index.php on line 298

Notice: Undefined variable: items in C:\Apache2\htdocs\pcplus\index.php on line 13

Notice: Undefined variable: total_price in C:\Apache2\htdocs\pcplus\index.php on line 14

and It doesn't shows me the content of the query.

 
I don't see where you are initializing $catid. Is this variable supposed to be from a submitted form?

If so, I strongly recommend that you use $_POST['catid'] or $_GET['catid'], depending on whether the "method" attribute of the form being submitted.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I already tried that, and still appears the messages. and doesn't shows me anything.

Regards.
 
In all modern versions of PHP, the default setting for register_globals is "off". This is for very good reasons talked about in the PHP online manual:
If you have an HTML form with a field named "catid" and if register_globals is set to "off", $catid will never exist in your script, and any references to the variable in a function call or an expression will generate the warnings you are seeing.


Is $catid supposed to come from a form?
Is your register_globals correctly set to "off"?
Does your HTML form have a "POST" method?
Does your HTML form have an input named "catid"?



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hello,

Yes. $catid comes from url (GET).
I have a categories menu, where the links are:
index.php?catid=2
index.php?catid=3... etc.

the register_globals are set to Off, But before, when the website worked fine, was set to On. I made the test activating the register_global On again, but it doesn't work either.

I already tried to get this variables like $catid=$_GET["catid"]; but, still not working. And also I've tried $catid=$_REQUEST["catid"]; and I have the same results.

Thanks you.


 
What version of PHP are you running?

Have you tried having your form submit to a script which outputs all variables?

Something like:

Code:
<?php
print '<html><body>';

print '$_GET:<pre>';
print_r ($_GET);
print '</pre>';

print '$_POST:<pre>';
print_r ($_POST);
print '</pre>';

print '$_SERVER:<pre>';
print_r ($_SERVER);
print '</pre>';


print '</body></html>';
?>



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top