Showing posts with label database connection in php. Show all posts
Showing posts with label database connection in php. Show all posts

Tuesday, 9 July 2013

Get data From data base in php mysql

// Get data From data base in php mysql

<?php
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("bnr");
$sql="select *from reg";
$query=mysql_query($sql);
while($row = mysql_fetch_array($query))
  {
  $username=$row['username'];
  echo  $row['username'] 
  echo  $row['name'] 
  echo  $row['password'] 
  echo  $row['emp_id'] 
  echo  $row['phone_no'] 
  echo  $row['email_id'] 
  echo  $row['address'] 
  }
mysql_close($con);
?>
<html>
<head></head>
<body>
</body>
</html>

Get data from Mysql DataBase in PHP (Display in Table)

// Get data from Mysql DataBase in PHP (Display in Table)

<?php
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("bnr");
$sql="select *from reg";
$query=mysql_query($sql);

 echo "<table border='1'>
<tr>
<th>User Name</th>
<th>Name</th>
<th>password</th>
<th>Emp ID</th>
<th>Phone No</th>
<th>Email ID</th>
<th>Address</th>
</tr>";

while($row = mysql_fetch_array($query))
  {
 $username=$row['username'];
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['password'] . "</td>";
  echo "<td>" . $row['emp_id'] . "</td>";
  echo "<td>" . $row['phone_no'] . "</td>";
  echo "<td>" . $row['email_id'] . "</td>";
  echo "<td>" . $row['address'] . "</td>";
  echo "</tr>";
  }

mysql_close($con);




?>
</table>
<html>
<head></head>
<body>
</body>
</html>

Thursday, 4 July 2013

Syntax of Data Base connection using mysql in php



<?php
$con=mysql_connect("servername","username","password");
// ex: $con=mysql_connect("localhost","root","");
$db=mysql_select_db("database name");
$sql="sql query";
$query=mysql_query($sql);

?>