0

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....

5
  • What error do you get? Commented Nov 4, 2016 at 7:28
  • blank page i am getting Commented Nov 4, 2016 at 7:28
  • First do not use mysql, ude mysqli if you just started learning PHP. More information can be found php.net/manual/en/book.mysqli.php Commented Nov 4, 2016 at 7:30
  • you should write session_start on top of file ,This is recommended to you !!! Commented Nov 4, 2016 at 7:30
  • 1
    Anytime you are getting a blank page, add error_reporting(E_ALL); ini_set('display_errors', 1); at the top Commented Nov 4, 2016 at 7:32

1 Answer 1

2

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());
Sign up to request clarification or add additional context in comments.

3 Comments

The first two lines of code I used came from what you've posted. You need to remove mysql_query on the first part or remove the second part.
ha its working but i need table format but it displaying in normal
@VenuBollu It should show a table, check the source code in your browser to see what he got. You are missing the <tr> on the table headers, but besides the header the rest should appear in a table layout.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.