Reputation: 29
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.
Upvotes: 1
Views: 2130
Reputation: 3138
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
}
}
Upvotes: 0
Reputation: 219934
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;
Upvotes: 5