connection.inc.php :
<?php
$host='localhost';
$user_name='root';
$password='';
@$con = mysql_connect("$host","$user_name","$password");
if ($con)
{}
else
{
die('Could not connect ');
}
?>
=======================================================================
select_form.php :
<center><form action="select_table.php" method="POST">
<table border=0><tr><td>database name</td><td><input type="text" name="db_name" value="test"></td>
<td>table name</td><td><input type="text" name="table_name" value="test"></td></tr>
<tr><td>column1 name</td><td><input type="text" name="col1" value="sno"></td>
<td>column2 name</td><td><input type="text" name="col2" value="name"></td></tr>
<tr><td colspan=4 align="center"><input type="submit" value="submit"> </td></tr></table>
</form>
===================================================================
select_table.php :
<?php
require 'connection.inc.php';
if (@mysql_select_db($_POST['db_name']))
{
if(isset($_POST['db_name'])&& isset($_POST['table_name'])&& isset($_POST['col1'])&& isset($_POST['col2']))
{
if(!empty($_POST['db_name'])&& !empty($_POST['table_name'])&& !empty($_POST['col1'])&& !empty($_POST['col2']))
{
$db=$_POST['db_name'];
$tn=$_POST['table_name'];
$snum=$_POST['col1'];
$name=$_POST['col2'];
$result=mysql_query("select * from $tn ",$con);
if(mysql_query("select * from $tn ",$con))
{
if(@mysql_num_rows($result))
{
echo ("<br><center><table><tr><th><b>$snum</td><th><b>$name</td></tr>");
if(mysql_query("select $snum from $tn") && mysql_query("select $name from $tn"))
{
while($data = mysql_fetch_array($result))
{
echo "<tr><td>".@$data[$snum] . "</td><td>" .@$data[$name]."</td></tr>";
}
}else {
echo '<b>please verify column name(s)</b>';
}
} else echo '<center><b>empty table';
} else echo ('<center><br><br><b>no table with that name<br><br>');
}
else echo '<center>please varify is all data entered ?';
} else echo '<center>one of the input ont set';
}else echo '<center><br>wrong database selected<br>';
mysql_close($con);
?>
<?php
$host='localhost';
$user_name='root';
$password='';
@$con = mysql_connect("$host","$user_name","$password");
if ($con)
{}
else
{
die('Could not connect ');
}
?>
=======================================================================
select_form.php :
<center><form action="select_table.php" method="POST">
<table border=0><tr><td>database name</td><td><input type="text" name="db_name" value="test"></td>
<td>table name</td><td><input type="text" name="table_name" value="test"></td></tr>
<tr><td>column1 name</td><td><input type="text" name="col1" value="sno"></td>
<td>column2 name</td><td><input type="text" name="col2" value="name"></td></tr>
<tr><td colspan=4 align="center"><input type="submit" value="submit"> </td></tr></table>
</form>
===================================================================
select_table.php :
<?php
require 'connection.inc.php';
if (@mysql_select_db($_POST['db_name']))
{
if(isset($_POST['db_name'])&& isset($_POST['table_name'])&& isset($_POST['col1'])&& isset($_POST['col2']))
{
if(!empty($_POST['db_name'])&& !empty($_POST['table_name'])&& !empty($_POST['col1'])&& !empty($_POST['col2']))
{
$db=$_POST['db_name'];
$tn=$_POST['table_name'];
$snum=$_POST['col1'];
$name=$_POST['col2'];
$result=mysql_query("select * from $tn ",$con);
if(mysql_query("select * from $tn ",$con))
{
if(@mysql_num_rows($result))
{
echo ("<br><center><table><tr><th><b>$snum</td><th><b>$name</td></tr>");
if(mysql_query("select $snum from $tn") && mysql_query("select $name from $tn"))
{
while($data = mysql_fetch_array($result))
{
echo "<tr><td>".@$data[$snum] . "</td><td>" .@$data[$name]."</td></tr>";
}
}else {
echo '<b>please verify column name(s)</b>';
}
} else echo '<center><b>empty table';
} else echo ('<center><br><br><b>no table with that name<br><br>');
}
else echo '<center>please varify is all data entered ?';
} else echo '<center>one of the input ont set';
}else echo '<center><br>wrong database selected<br>';
mysql_close($con);
?>
=======================================================================
run " select_form.php "
output :
fill every text box and click on submit button