如何显示数据从数据库在HTML文本框使用php


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

我在HTML页面显示我的表数据,但我得到空白页.....

我是新的PHP编码请帮助我.....

这是我的HTML代码

<!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>
这是我的PHP代码
<!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>

我得到错误只有空白页面显示…请帮帮我....

您使用了两次mysql_query()。改变这个:

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

为:

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