"Notice: Undefined index"?
Posted: Tue Jul 10, 2007 6:59 pm
I know I can disable Notice's from within my php.ini, but I want to resolve this issue with better code.
index.php:
lib.php:
My error message:
index.php:
Code: Select all
<?php
require_once("lib.php");
// connect and select a database
dbconnect();
// assign passed variables
// discover current category
if(!isset($dbh)) $dbh = $_REQUEST['dbh'];
else die("Error: dbh not available");
?>lib.php:
Code: Select all
<?php
// connect and select a database
function dbconnect()
{ if (!(isset($dbh)))
{ if ($dbh = mysql_connect('localhost', 'root', ''))
mysql_select_db('new', $dbh);
else
echo "<p>ERROR: Connection failed</p>";
}
}
?>My error message:
Notice: Undefined index: dbh in /var/www/html/test/index.php on line 12