Venu Bollu Venu Bollu - 1 month ago 6
PHP Question

how to display data from database in html text boxes using php

i am displaying my table data in html page but i am getting blank page.....

i am new to php coding please help me.....

this is my html code

<!DOCTYPE html>
<html>
<head>
<script>
function validate(){
var phonenumber=document.myform.phonenumber.value;
if(phonenumber.length>=10){
alert("Phonenumber must be at least 10 characters");
return false;
}
}
</script>
</head>
<body font-color="red">
<form name ="myform" action="dis.php" method="post" submit="return validate()">

<table border='0' width='480px' cellpadding='0' cellspacing='0' align='center'>
<center><tr>
<td><h1><marquee> Employee Details</marquee></h1></td>
</tr><center>

<table border='0' width='480px' cellpadding='0' cellspacing='0' align='center'>
<tr>
<td align='center'>Name:</td>
<td><input type='text' name='name' required></td>
</tr>
<tr> <td>&nbsp;</td> </tr>
<tr>
<td align='center'>id:</td>
<td><input type='text' name='id'></td>
</tr>
<tr> <td>&nbsp;</td> </tr>
<tr>
<td align='center'>roll number:</td>
<td><input type='text' name='rollnumber'></td>
</tr>
<tr> <td>&nbsp;</td> </tr>
<tr>
<td align='center'>Address:</td>
<td><input type='text' name='address'></td>
</tr>
<tr> <td>&nbsp;</td> </tr>
<tr>
<td align='center'>Phonenumber:</td>
<td><input type='text' name='phonenumber'></td>
</tr>
<tr> <td>&nbsp;</td> </tr>
<table border='0' cellpadding='0' cellspacing='0' width='480px' align='center'>
<tr>
<td align='center'><input type='submit' name='insert' value="insert"></td>
</tr>
<tr>
<td align='center'><input type='submit' name='update' value="update"></td>
</tr>
</table>
</table>

</table>
</form>
</body>
</html>


this is my php code

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
$connection = mysql_connect('localhost', 'root','');
if (!$connection)
{
die("Database Connection Failed" . mysql_error());
}
$select_db = mysql_select_db( "emp",$connection);
if (!$select_db)
{
die("Database Selection Failed" . mysql_error());
}
else
{
session_start();
error_reporting(0);
$name = $_POST['name'];
$id = $_POST['id'];
$rollnumber = $_POST['rollnumber'];
$address = $_POST['address'];
$phonenumber = $_POST['phonenumber'];

if(isset($_POST['insert']))
{
$sql = mysql_query("SELECT * FROM venu ");
$result = mysql_query($sql) or die(mysql_error());
$n=mysql_num_rows($result);
if($n > 0)
{
echo "<table>";
echo "<th>name</th>";
echo "<th>id</th>";
echo "<th>rollnumber</th>";
echo "<th>address</th>";
echo "<th>phonenumber</th>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['rollnumber'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['phonenumber'] . "</td>";
echo "</tr>";
}
echo "</table>";

}
else
{
echo "No records matching your query were found.";
}
}
else
{
echo "ERROR: Could not able to execute.";
}
}
mysql_close($connection);
?>
</body>
</html>


i am getting error
only blank page displaying...
please help me....

Answer

You are using mysql_query() twice. Change this:

$sql = mysql_query("SELECT * FROM venu ");     
$result = mysql_query($sql) or die(mysql_error());

Into:

$sql = "SELECT * FROM venu ";     
$result = mysql_query($sql) or die(mysql_error());
Comments