Monday, 24 November 2008

php program to create table insert data and show data in tabular format

< ? php

$dbhost="localhost";

$dbname="root";

$dbpass="123";

$rs=mysql_connect($dbhost,$dbname,$dbpass);

$nm=$_POST['n1'];$rl=$_POST['n2'];

//This is to check whether connection established or not

//if($rs)

//echo "Connected ";

//else

//echo "Not Connected";

$ds=mysql_select_db(test);

//This is to check whether database connected or not

//if($ds)

//echo "connected to database";

//else

///echo "Not connected to database";$ts=mysql_query("create table student (name varchar(50),roll_no int(10))");

//this is to check whether query run successfully or notif($ts)echo "Table is created";

//else

//echo "Table is not created";

$is=mysql_query("insert into student values('$nm',$rl)");

//This is to check the execution of Insert Command

//if($is)

//echo "Insert is working";

//else

//echo "Insert is not working"; $sl=mysql_query("select * from student");

print '<.table border=2 color="red">';

print '<.th> Name<.th>Roll_No';

print '<.tr>';

while($info=mysql_fetch_array($sl))

{

print '<.td> '.$info['name'].'';

print '<.td>'.$info['roll_no'].'<./td>';

print '<./tr>';

}

print '<./table>';

? >

No comments: