Hello ! I am new in php coding. So if you please help me in this regards I'll be very happy.
I have received some error while connection to my mqsql database to a php file. At first I post my code....
"login.php"
<?php
$db_hostname = 'localhost' ;
$db_database = 'PC' ;
$db_username = 'admin' ;
$db_password = 'maruf' ;
?>
"func.php"
<?php
require_once('C:\xampp\htdocs\PC\login.php') ;
function connect(){
$db_server = mysql_connect( $db_hostname , $db_username , $db_password ) ;
if( !$db_server )die ( "Unable to connect to MySql : ".mysql_error()) ;
mysql_select_db( $db_database ) or die("Unable to select database: ".mysql_error()) ;
}
function close(){
mysql_close() ;
}
function division(){
$mydata = mysql_query("SELECT * from division order by zeocode");
if( !$mydata ) echo "Database connection failed. ".mysql_error().'<br>' ;
while( $record = mysql_fetch_array($mydata)){
echo '<option value ="' . $record['$name'] . '">' . $record['$name'] . '"</option>';
}
}
?>
"form.php"
<?php
require_once 'func.php';
connect() ;
?>
<!DOCTYPE html>
<html>
<head>
form
</head>
<body>
<header> <h1 align='center'>Census</h1></header>
<p>
<select name ="division">
<?php query() ?>
</select>
<?php close() ?>
</p>
</body>
</html>
It shows me the following error .
calling from the browser -> http://localhost/PC/form.php
Notice: Undefined variable: db_hostname in C:\xampp\htdocs\Population_Census\func.php on line 10
Notice: Undefined variable: db_username in C:\xampp\htdocs\Population_Census\func.php on line 10
Notice: Undefined variable: db_password in C:\xampp\htdocs\Population_Census\func.php on line 10
Notice: Undefined variable: db_database in C:\xampp\htdocs\Population_Census\func.php on line 12
Unable to select database: No database selected
then I change form.php into this
<?php
//require_once('C:\xampp\htdocs\Population_Census\login.php') ;
$db_hostname = 'localhost' ;
$db_database = 'PC' ;
$db_username = 'admin' ;
$db_password = 'maruf' ;
function connect(){
$db_server = mysql_connect( $db_hostname , $db_username , $db_password ) ;
if( !$db_server )die ( "Unable to connect to MySql : ".mysql_error()) ;
mysql_select_db( $db_database ) or die("Unable to select database: ".mysql_error()) ;
}
function close(){
mysql_close() ;
}
function division(){
$mydata = mysql_query("SELECT * from division order by zeocode");
if( !$mydata ) echo "Database connection failed. ".mysql_error().'<br>' ;
while( $record = mysql_fetch_array($mydata)){
echo '<option value ="' . $record['$name'] . '">' . $record['$name'] . '"</option>';
}
}
?>
which show me exactly same problem.