0

This weekend I formatted and reinstalled my computer: today when I try to continue working on some php pages I've been programming last weeks, when I execute the php code on the localhost server I get an:

"Notice: Undefined variable: consulta in D:\WEBS\WP\lbodas.php on line 42 1 de enero de 1970"

It's happening on all the php pages that perform an SQL query (wich worked perfectly before the reinstall).

I must be missing some configuration tweak (on php.ini, httpd.conf or some other apache configuration file), can somebody point me out what I'm missing?

Thanks in advance


Here is the code I'm using. To conect to the DDBB:

$bd_host='localhost';
$bd_login='MYLOGIN';  
$bd_clave='MYPASSWORD';
$bd_nombre='MYDATABASE';

connecttodb($bd_host,$bd_nombre,$bd_login,$bd_clave);
function connecttodb($bd_host,$bd_nombre,$dbuser,$bd_clave)
{
    global $conn;
    $conn=mysql_connect ("$bd_host","$dbuser","$bd_clave");
    mysql_query("SET NAMES 'utf8'");
    if(!$conn){die("CONNECTION ERROR");}
    //mysql_query("SET NAMES 'utf8'");

    mysql_select_db("$bd_nombre",$conn) or die ("CONNECTION ERROR".mysql_error());
}

And one of the sql queries that used to work but after the reinstall doesn't work:

        $sql = "SELECT * FROM cat_prov ORDER BY categoria ASC";
        $rs_result = mysql_query ($sql, $conn);

        while ($row = mysql_fetch_assoc($rs_result)) {
            $categoria=$row["categoria"];
            $notas=$row["notas"];
        }        

It's saying that the $row variable, wich holds the array with the results of the sql query, hasn't been defined... but two days ago, before the server OS reinstall I didn't have to define variables!!

4
  • 2
    share some code to help you better Commented May 13, 2013 at 13:47
  • show the code, but right away i'm thinking of the register_globals parameter that you should not use anyway. Commented May 13, 2013 at 13:47
  • 1
    your have notices enabled so its warning you about not declaring variables before using them Commented May 13, 2013 at 13:48
  • Tried changing the register_globals parameter = no success Tried disabling notices (changed it to [E_ALL & ~E_NOTICE & ~E_STRICT]) and doesn't show the error, but doesn't show results either... I've posted some code below Commented May 14, 2013 at 18:16

2 Answers 2

1

Your new installation has error reporting set to E_ALL which is also displaying notices. Try

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

Source: PHP Manual

Sign up to request clarification or add additional context in comments.

Comments

0

You're probably doing something like

$result = $consulta + 1;

without ever having assigned a value to $consulta before this. Anytime you use a variable in a "read" context, without having first assigned it, newer versions of PHP will throw that warning.

Doing

$consult = 0;
$result = $consulta + 1;

will solve the problem, becase you've defined a value for the variable BEFORE it was used in a read context.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.