DWPD : Practical 23
This Application Contains Following Files :
• Register.php
• Login.php
• Welcome.php
• Edit-profile.php
• Logout.php
• config.php
<?php
session_start();
if(isset($_SESSION['user']))
{
header("location:welcome.php");
}
include("config.php");
?>
<html>
<head>
<title>Registration</title>
</head>
<body>
<h3>Registration</h3>
<form method="post">
<table>
<tr>
<td>Name</td>
<td>
<input type="text" name="name">
</td>
</tr>
<tr>
<td>Department</td>
<td>
<select name="dept">
<option value="Computer Engineering">Computer Engineering</option>
<option value="Civil Engineering">Civil Engineering</option>
<option value="Mechanical Engineering">Mechanical Engineering</option>
</select>
</td>
</tr>
<tr>
<td>Semester</td>
<td>
<select name="sem">
<option value="1">1</option>
<option value="2">2</option>
<option value="2">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</td>
</tr>
<tr>
<td>Email</td>
<td>
<input type="email" name="email">
</td>
<tr>
<td>Password</td>
<td>
<input type="Password" name="pass">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="submit" value="register">
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$nm=$_POST['name'];
$dpt=$_POST['dept'];
$sm=$_POST['sem'];
$em=$_POST['email'];
$pwd=$_POST['pass'];
$sql="SELECT * FROM users WHERE email='$em'";
$query=mysql_query($sql);
$count=mysql_num_rows($query);
if($count>=1)
{
echo "email already registered please use different email";
}
else
{
$sql="INSERT INTO users(name,dept,sem,email,pass) VALUES('$nm','$dpt','$sm','$em','$pwd')";
$reg=mysql_query($sql);
$_SESSION['user']=$em;
header("location:welcome.php");
}
}
?>
Output :
<?php
session_start();
if(isset($_SESSION['user']))
{
header("location:welcome.php");
}
include("config.php");
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<h3>Login</h3>
<form method="post">
<table>
<tr>
<td>Email</td>
<td>
<input type="email" name="email">
</td>
<tr>
<td>Password</td>
<td>
<input type="Password" name="pass">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="login" value="Login">
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['login']))
{
$em=$_POST['email'];
$pwd=$_POST['pass'];
$sql="SELECT * FROM users WHERE email='$em' && pass='$pwd'";
$query=mysql_query($sql);
$count=mysql_num_rows($query);
if($count==1)
{
$_SESSION['user']=$em;
header("location:welcome.php");
}
else
{
echo "Invalid Login";
}
}
?>
Output :
<?php
session_start();
include("config.php");
if(!(isset($_SESSION['user'])))
{
header("location:login.php");
}
$em=$_SESSION['user'];
$sql="SELECT * FROM users where email='$em'";
$query=mysql_query($sql);
while($raw=mysql_fetch_assoc($query))
{
echo "<h3>Welcome ".$raw['name']."</h3>";
echo "<h3>email : ".$raw['email']."</h3>";
echo "<h3>Department : ".$raw['dept']."</h3>";
echo "<h3>Semester : ".$raw['sem']."</h3>";
}
?>
<a href="logout.php">Logout</a><br>
<a href="edit-profile.php">edit Profile</a><br>
Output :
<?php
session_start();
include("config.php");
if(!(isset($_SESSION['user'])))
{
header("location:login.php");
}
$em=$_SESSION['user'];
$sql="SELECT * FROM users where email='$em'";
$query=mysql_query($sql);
while($raw=mysql_fetch_assoc($query))
{
?>
<body>
<h3>Edit Profile</h3>
<form method="post">
<table>
<tr>
<td>Name</td>
<td>
<input type="text" name="name" value="<?php echo $raw['name']; ?>">
</td>
</tr>
<tr>
<td>Department</td>
<td>
<select name="dept">
<option value="<?php echo $raw['dept']; ?>"><?php echo $raw['dept']; ?></option>
<option value="Computer Engineering">Computer Engineering</option>
<option value="Civil Engineering">Civil Engineering</option>
<option value="Mechanical Engineering">Mechanical Engineering</option>
</select>
</td>
</tr>
<tr>
<td>Semester</td>
<td>
<select name="sem">
<option value="<?php echo $raw['sem']; ?>"><?php echo $raw['sem']; ?></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="2">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</td>
</tr>
<tr>
<td>Email</td>
<td>
<input type="email" name="email" value="<?php echo $raw['email']; ?>">
</td>
<tr>
<td>Password</td>
<td>
<input type="Password" name="pass" value="<?php echo $raw['pass']; ?>">
<input type="hidden" name="uid" value="<?php echo $raw['id']; ?>">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="update" value="Update Profile">
</td>
</tr>
</table>
</form>
<a href="welcome.php">Home</a><br>
<a href="Logout.php">Logout</a>
</body>
</html>
<?php
}
if(isset($_POST['update']))
{
$sid=$_POST['uid'];
$nm=$_POST['name'];
$dpt=$_POST['dept'];
$sm=$_POST['sem'];
$em=$_POST['email'];
$pwd=$_POST['pass'];
$sql="UPDATE users SET name='$nm', dept='$dpt', sem='$sm', email='$em', pass='$pwd' WHERE users.id='$sid' LIMIT 1";
$query=mysql_query($sql)or die("failed");
if($query)
{
header("location:edit-profile.php");
}
}
?>
Output :
<?php
session_start();
session_destroy();
header("location:login.php");
?>
<?php
$con=mysql_connect('localhost','root','');
mysql_select_db("cart",$con);
?>
This comment has been removed by a blog administrator.
ReplyDeletethank you
ReplyDeletedatabase ka aur table ka kaya name rakhna hai
ReplyDeleteDatabase name : cart
DeleteTable name : users