1

I'm trying to bring a old script that was encrypted and shut down back to life but i'm not the best at php but practice makes prefect.

I've just decoded it and going though the installation process and i'm getting PHP Notices Undefined variable.

[21-Sep-2013 17:51:56 Europe/Berlin] PHP Notice:  Undefined variable: dberror in C:\xampp\htdocs\install\step1.php on line 7
[21-Sep-2013 17:51:56 Europe/Berlin] PHP Notice:  Undefined variable: dberror in C:\xampp\htdocs\install\step1.php on line 10


  <?php

     if (isset($setdb)) {
          if (( ( ( $dbhost && $dbuser ) && $dbpass ) && $dbname )) {
              ( @mysql_connect( $dbhost, $dbuser, $dbpass ) || $dberror = 'Can\'t connect to database server' );

               if (!$dberror) {
               ( @mysql_select_db( $dbname ) || $dberror = 'Can\'t select database' );

                     if (!$dberror) {
                         @session_register( 'dbhost' );
                         @session_register( 'dbuser' );
                         @session_register( 'dbpass' );
                         @session_register( 'dbname' );
                         $_SESSION['dbhost'] = $dbhost;
                         $_SESSION['dbuser'] = $dbuser;
                         $_SESSION['dbpass'] = $dbpass;
                         $_SESSION['dbname'] = $dbname;
                         print '<script> window.location=\'index.php?menu=step2\';  </script>';
                      }
                   }
               }
         else {
              $dberror = 'All fields are required';
      }
  }

Could someone tell me what is wrong please.

1
  • If there is no error, $dberror will never be defined. Commented Sep 21, 2013 at 16:13

2 Answers 2

5

This is because if no error occurs, $dberror is never defined.

if (!$dberror) {

should be:

if (!isset($dberror)) {

OR

Add this to the top of the page (recommended):

$dberror = false;
Sign up to request clarification or add additional context in comments.

Comments

0

The variable $dberror was not defined before it was used in your "IF" statement.

The script does not have any information about $dberror before it could check for if(!$dberror). It appears meaningless to check if a variable has any value without being declared or assigned before.

IF this is what you still want, you can check if the variable is declared at all before you can check if it has a value using isset

if(isset($dberror)){
  if(!$dberror){
  // your stuff
}

}

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.