Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

Tuesday, 9 July 2013

Login Page In PHP Mysql using sessions

// Login Page In PHP Mysql using sessions

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<?php
session_start();
if(isset($_POST['sub']))
{
$username=$_POST['username'];
$password=$_POST['password'];
$con=mysql_connect("localhost", "root", "")or die("cannot connect");
  $db=mysql_select_db("bnr");
  $sql="SELECT * FROM login
WHERE name='$username' and password='$password'";
  $query=mysql_query("$sql");
  $count=mysql_num_rows($query);
   
    if($count!=0)
{
//session_register("name");
     // session_register("password");
 

$_SESSION['out']=true;
echo "Login Success";

}
else
echo "<font color='#FF0000'>invalid</font>";
}
?>

</head>
<body>

<form action="" method="post" id="form1" name="form1" enctype="multipart/form-data" >
username:<input type="text" name="username" id="username" />
<br />
password:<input type="password" name="password" id="password" />
<br />
<input type="submit" value="login" name="sub" />
</form>
</body>
</html>

Login Page In PHP Mysql using sessions and java script

// Login Page In PHP Mysql using sessions and java script

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
function uservalid()
{
var name = document.form1.username.value;
if(name =="")
{
alert("Please Enter Name");
document.form1.focus();
return false;
}
}</script>
<?php
session_start();
if(isset($_POST['sub']))
{
$username=$_POST['username'];
$password=$_POST['password'];
$con=mysql_connect("localhost", "root", "")or die("cannot connect");
  $db=mysql_select_db("bnr");
  $sql="SELECT * FROM login
WHERE name='$username' and password='$password'";
  $query=mysql_query("$sql");
  $count=mysql_num_rows($query);
   
    if($count!=0)
{
//session_register("name");
     // session_register("password");


$_SESSION['out']=true;
echo "Login Success";

}
else
echo "<font color='#FF0000'>invalid</font>";
}
?>

</head>
<body>

<form action="" method="post" id="form1" name="form1" enctype="multipart/form-data" onsubmit="return uservalid()">
username:<input type="text" name="username" id="username" />
<br />
password:<input type="password" name="password" id="password" />
<br />
<input type="submit" value="login" name="sub" />
</form>
</body>
</html>

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);

?>