connection.inc.php :
<?php
$host='localhost';
$user_name='root';
$password='';
@$con = mysql_connect("$host","$user_name","$password");
if ($con)
{echo '<br>host coonected<br>';}
else
{
die('Could not connect ');
}
?>
insert_table.php :
<?php
require 'connection.inc.php';
if (mysql_select_db('test'))
echo '<br>database selected<br>';
if(mysql_query("insert into test(sno,name)values (2,'human')",$con))
{
echo "<br>data inserted<br>";
}
else
{
echo '<br>data not inserted :'.mysql_error().'<br>';
}
mysql_close($con);
?>
run " insert_table.php "
output :
host coonected
database selected
data inserted
<?php
$host='localhost';
$user_name='root';
$password='';
@$con = mysql_connect("$host","$user_name","$password");
if ($con)
{echo '<br>host coonected<br>';}
else
{
die('Could not connect ');
}
?>
insert_table.php :
<?php
require 'connection.inc.php';
if (mysql_select_db('test'))
echo '<br>database selected<br>';
if(mysql_query("insert into test(sno,name)values (2,'human')",$con))
{
echo "<br>data inserted<br>";
}
else
{
echo '<br>data not inserted :'.mysql_error().'<br>';
}
mysql_close($con);
?>
run " insert_table.php "
output :
host coonected
database selected
data inserted