Tuesday 1 December 2015

create page (auth.php)

<?php
session_start();
if(!isset($_SESSION["username"])){
header("Location: login.php");
exit(); }
?>

create page (dashbord.php)

<?php
require('db.php');
include("auth.php"); //include auth.php file on all secure pages ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dashboard - View Records</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="form">
<p>Welcome to Dashboard.</p>
<p><a href="index.php">Home</a><p>
<p><a href="insert.php">Insert New Record</a></p>
<p><a href="view.php">View Records</a><p>
<p><a href="logout.php">Logout</a></p>
</div>
</body>

</html>

create page (db.php)

<?php
$connection = mysql_connect('localhost', 'root', '');
if (!$connection){
    die("Database Connection Failed" . mysql_error());
}
$select_db = mysql_select_db('login');
if (!$select_db){
    die("Database Selection Failed" . mysql_error());
}

?>

create page (delete.php)

<?php 
require('db.php');
$id=$_REQUEST['id'];
$query = "DELETE FROM new_record WHERE id=$id"; 
$result = mysql_query($query) or die ( mysql_error());
header("Location: view.php"); 
 ?>

create page (edit.php)

<?php 
require('db.php');
include("auth.php");
$id=$_REQUEST['id'];
$query = "SELECT * from new_record where id='".$id."'"; 
$result = mysql_query($query) or die ( mysql_error());
$row = mysql_fetch_assoc($result);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Update Record</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="form">
<p><a href="dashboard.php">Dashboard</a> | <a href="insert.php">Insert New Record</a> | <a href="logout.php">Logout</a></p>
<h1>Update Record</h1>
<?php
$status = "";
if(isset($_POST['new']) && $_POST['new']==1)
{
$id=$_REQUEST['id'];
$trn_date = date("Y-m-d H:i:s");
$name =$_REQUEST['name'];
$age =$_REQUEST['age'];
$submittedby = $_SESSION["username"];
$update="update new_record set trn_date='".$trn_date."', name='".$name."', age='".$age."', submittedby='".$submittedby."' where id='".$id."'";
mysql_query($update) or die(mysql_error());
$status = "Record Updated Successfully. </br></br><a href='view.php'>View Updated Record</a>";
echo '<p style="color:#FF0000;">'.$status.'</p>';
}else {
?>
<div>
<form name="form" method="post" action=""> 
<input type="hidden" name="new" value="1" />
<input name="id" type="hidden" value="<?php echo $row['id'];?>" />
<p><input type="text" name="name" placeholder="Enter Name" required value="<?php echo $row['name'];?>" /></p>
<p><input type="text" name="age" placeholder="Enter Age" required value="<?php echo $row['age'];?>" /></p>
<p><input name="submit" type="submit" value="Update" /></p>
</form>
<?php } ?>
</div>
</div>
</body>
</html>


create page (index.php)



<?php include("auth.php"); //include auth.php file on all secure pages ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Welcome Home</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="form">
<p>Welcome <?php echo $_SESSION['username']; ?>!</p>
<p>This is secure area.</p>
<p><a href="dashboard.php">Dashboard</a></p>
<a href="logout.php">Logout</a>
</div>
</body>
</html>

create page (insert.php)
<?php
require('db.php');
include("auth.php"); //include auth.php file on all secure pages
$status = "";
if(isset($_POST['new']) && $_POST['new']==1)
{
$trn_date = date("Y-m-d H:i:s");
$name =$_REQUEST['name'];
$age = $_REQUEST['age'];
$submittedby = $_SESSION["username"];
$ins_query="insert into new_record(`trn_date`,`name`,`age`,`submittedby`)values('$trn_date','$name','$age','$submittedby')";
mysql_query($ins_query) or die(mysql_error());
$status = "New Record Inserted Successfully.</br></br><a href='view.php'>View Inserted Record</a>";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert New Record</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="form">
<p><a href="dashboard.php">Dashboard</a> | <a href="view.php">View Records</a> | <a href="logout.php">Logout</a></p>
<div>
<h1>Insert New Record</h1>
<form name="form" method="post" action=""> 
<input type="hidden" name="new" value="1" />
<p><input type="text" name="name" placeholder="Enter Name" required /></p>
<p><input type="text" name="age" placeholder="Enter Age" required /></p>
<p><input name="submit" type="submit" value="Submit" /></p>
</form>
<p style="color:#FF0000;"><?php echo $status; ?></p>
</div>
</div>
</body>
</html>

create page (login.php)

<?php
/*
Author: Javed Ur Rehman
Website: https://htmlcssphptutorial.wordpress.com
*/
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
require('db.php');
session_start();
    // If form submitted, insert values into the database.
    if (isset($_POST['username'])){
        $username = $_POST['username'];
        $password = $_POST['password'];
$username = stripslashes($username);
$username = mysql_real_escape_string($username);
$password = stripslashes($password);
$password = mysql_real_escape_string($password);
//Checking is user existing in the database or not
        $query = "SELECT * FROM `users1` WHERE username='$username' and password='".md5($password)."'";
$result = mysql_query($query) or die(mysql_error());
$rows = mysql_num_rows($result);
        if($rows==1){
$_SESSION['username'] = $username;
header("Location: index.php"); // Redirect user to index.php
            }else{
echo "<div class='form'><h3>Username/password is incorrect.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
}
    }else{
?>
<div class="form">
<h1>Log In</h1>
<form action="" method="post" name="login">
<input type="text" name="username" placeholder="Username" required />
<input type="password" name="password" placeholder="Password" required />
<input name="submit" type="submit" value="Login" />
</form>
<p>Not registered yet? <a href='registration.php'>Register Here</a></p>
</div>
<?php } ?>
</body>
</html>


create page (logout.php)

<?php
session_start();
if(session_destroy()) // Destroying All Sessions
{
header("Location: login.php"); // Redirecting To Home Page
}
?>

create page (registration.php)


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Registration</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
require('db.php');
    // If form submitted, insert values into the database.
    if (isset($_POST['username'])){
        $username = $_POST['username'];
$email = $_POST['email'];
        $password = $_POST['password'];
$username = stripslashes($username);
$username = mysql_real_escape_string($username);
$email = stripslashes($email);
$email = mysql_real_escape_string($email);
$password = stripslashes($password);
$password = mysql_real_escape_string($password);
$trn_date = date("Y-m-d H:i:s");
        $query = "INSERT into `users1` (username, password, email, trn_date) VALUES ('$username', '".md5($password)."', '$email', '$trn_date')";
        $result = mysql_query($query);
        if($result){
            echo "<div class='form'><h3>You are registered successfully.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
        }
    }else{
?>
<div class="form">
<h1>Registration</h1>
<form name="registration" action="" method="post">
<input type="text" name="username" placeholder="Username" required />
<input type="email" name="email" placeholder="Email" required />
<input type="password" name="password" placeholder="Password" required />
<input type="submit" name="submit" value="Register" />
</form>
</div>
<?php } ?>
</body>
</html>


create page (view.php)
<?php 
require('db.php');
include("auth.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>View Records</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="form">
<p><a href="index.php">Home</a> | <a href="insert.php">Insert New Record</a> | <a href="logout.php">Logout</a></p>
<h2>View Records</h2>
<table width="100%" border="1" style="border-collapse:collapse;">
<thead>
<tr><th><strong>S.No</strong></th><th><strong>Name</strong></th><th><strong>Age</strong></th><th><strong>Edit</strong></th><th><strong>Delete</strong></th></tr>
</thead>
<tbody>
<?php
$count=1;
$sel_query="Select * from new_record ORDER BY id desc;";
$result = mysql_query($sel_query);
while($row = mysql_fetch_assoc($result)) { ?>
<tr><td align="center"><?php echo $count; ?></td><td align="center"><?php echo $row["name"]; ?></td><td align="center"><?php echo $row["age"]; ?></td><td align="center"><a href="edit.php?id=<?php echo $row["id"]; ?>">Edit</a></td><td align="center"><a href="delete.php?id=<?php echo $row["id"]; ?>">Delete</a></td></tr>
<?php $count++; } ?>
</tbody>
</table>
</div>
</body>
</html>

Wednesday 11 November 2015

Insert update delete in DataGridView in C#

Insert update delete in DataGridView in C#




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AccountOpenning
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        DataTable dt = new DataTable();
        int i, j;
        int rowcount, sum;

        private void Form1_Load(object sender, EventArgs e)
        {
            dt.Columns.Add("S.No", typeof(int));
            dt.Columns.Add("Date", typeof(DateTime));
            dt.Columns.Add("Card No", typeof(int));
            dt.Columns.Add("Client Name", typeof(string));
            dt.Columns.Add("Product Name", typeof(string));
            dt.Columns.Add("Empty Bottle", typeof(int));
            dt.Columns.Add("Balance Account", typeof(int));
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            dt.Rows.Add(txtSno.Text, dateTimePicker1.Value, txtCno.Text, txtCname.Text, txtPname.Text, txtEbottle.Text, txtBaccount.Text);
            dataGridView1.DataSource = dt;

            txtSno.Text = null;
            txtCno.Text = null;
            txtCname.Text = null;
            txtEbottle.Text = null;
            txtPname.Text = null;
            txtBaccount.Text = null;
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                dt.Rows.RemoveAt(dataGridView1.CurrentCell.RowIndex);
                dataGridView1.DataSource = dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void DataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            i = e.RowIndex;
            DataGridViewRow row = dataGridView1.Rows[i];
            txtSno.Text = row.Cells[0].Value.ToString();
            dateTimePicker1.Format = DateTimePickerFormat.Custom;
            txtCno.Text = row.Cells[2].Value.ToString();
            txtCname.Text = row.Cells[3].Value.ToString();
            txtPname.Text = row.Cells[4].Value.ToString();
            txtEbottle.Text = row.Cells[5].Value.ToString();
            txtBaccount.Text = row.Cells[6].Value.ToString();
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            DataGridViewRow row = dataGridView1.Rows[i];
            row.Cells[0].Value = txtSno.Text;
            row.Cells[1].Value = dateTimePicker1.Text;
            row.Cells[2].Value = txtCno.Text;
            row.Cells[3].Value = txtCname.Text;
            row.Cells[4].Value = txtPname.Text;
            row.Cells[5].Value = txtEbottle.Text;
            row.Cells[6].Value = txtBaccount.Text;
        }
    }
}

Monday 9 November 2015

Insert, Update And Delete in ASP.NET



Data Base Design




create database Form

use Form

create table Employee
(
[ID] int identity primary key,
[Name] varchar (25),
[Email] varchar (25),
[Password] varchar (25),
);

select * from Employee


Insert, Update And Delete in ASP.NET






<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication6.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
        <br />
        <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
        <br />
        <asp:TextBox ID="txtPass" runat="server" TextMode="Password"></asp:TextBox>
        <br />
        <br />
        <asp:TextBox ID="txtUpdate" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:Button ID="btnInsert" runat="server" OnClick="btnInsert_Click" Text="Insert" />
        <asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click" />
        <asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="btnDelete_Click" />
   
    </div>
    </form>
</body>
</html>



Insert, Update And Delete Coding in ASP.NET


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Configuration;

namespace WebApplication6
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        string path = ConfigurationManager.ConnectionStrings["FormConnectionString"].ConnectionString;
        protected void btnInsert_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(path);
            SqlCommand cmd = new SqlCommand("insert into Employee values('" + txtName.Text + "','" + txtEmail.Text + "', '" + txtPass.Text + "')", con);
            con.Open();
            cmd.ExecuteNonQuery();

            txtName.Text = "";
            txtEmail.Text = "";
            txtPass.Text = "";
        }

        string Update = ConfigurationManager.ConnectionStrings["FormConnectionString"].ConnectionString;
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(Update);
            SqlCommand cmd = new SqlCommand("update Employee set Name='"+txtName.Text+"', Email='"+txtEmail.Text+"', Password='"+txtPass.Text+"' where id = '"+txtUpdate.Text+"' ", con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

            txtUpdate.Text = "";
            txtName.Text = "";
            txtEmail.Text = "";
            txtPass.Text = "";

        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(Update);
            SqlCommand cmd = new SqlCommand("delete from Employee where id = '" + txtUpdate.Text + "' ", con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

            txtUpdate.Text = "";
            txtName.Text = "";
            txtEmail.Text = "";
            txtPass.Text = "";
        }

       
    }
}


Wednesday 4 November 2015

Create Insert AND Update Form


DataBase Create




Create Insert AND Update Form





using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data.Sql;

namespace databaseconnection
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnInsert_Click(object sender, EventArgs e)
        {

         string path = "Data Source=.;Initial Catalog=connection;Persist Security Info=True;User ID=sa;Password=123";
         SqlConnection con = new SqlConnection(path);

         SqlCommand cmd = new SqlCommand("insert into Register values ('" + txtName.Text + "', '" + txtEmail.Text + "')", con);
         con.Open();
         cmd.ExecuteNonQuery();

         txtName.Text = "";
         txtEmail.Text = "";
            

            
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            string path = "Data Source=.;Initial Catalog=connection;Persist Security Info=True;User ID=sa;Password=123";
            SqlConnection con = new SqlConnection(path);

            SqlCommand cmd = new SqlCommand("UPDATE Register SET Name='" + txtName.Text + "',Email ='" + txtEmail.Text + "' where ID='"+txtUpdate.Text+"'", con);
            con.Open();
            cmd.ExecuteNonQuery();

            txtName.Text = "";
            txtEmail.Text = "";
            
        }
    }

}

Monday 26 October 2015

Data Transfer in asp.net



WebForm1 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ASPproject
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnTransfer_Click(object sender, EventArgs e)
        {
            Server.Transfer("WebForm2.aspx");
        }

        public string Name
        {
            get {
                return txtName.Text;
            }
     
        }
        public string Email
        {
            get {
                return txtEmail.Text;
            }
        }
    }
}






                                                                        WebForm2 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ASPproject
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Page lastPage=(Page)Context.Handler;
            //lblName.Text = ((TextBox)lastPage.FindControl("txtName")).Text;
            //lblEmail.Text = ((TextBox)lastPage.FindControl("txtEmail")).Text;


        }
    }
}

Wednesday 21 October 2015

Page Navigation Server.Transver








using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Asp_Project
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnTransfer_Click(object sender, EventArgs e)
        {
            Server.Transfer("~/WebForm2.aspx", false);
        }

        protected void btnredirec_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/WebForm2.aspx");
        }

     
    }
}














using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;

namespace Asp_Project
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //NameValueCollection previousformCollection = Request.Form;
            //lblName.Text = previousformCollection["txtName"];
            //lblEmail.Text = previousformCollection["txtEmail"];

            Page perviouspage = Page.PreviousPage;

            if (perviouspage != null)
            {
                lblName.Text = ((TextBox)perviouspage.FindControl("txtName")).Text;
                lblEmail.Text = ((TextBox)perviouspage.FindControl("txtName")).Text;
            }

         
         
        }
    }
}

Wednesday 7 October 2015

Login/Registration Form in C# window Application Form


Login.cs







using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace user_login
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=ASP4-PC\SQLEXPRESS;Initial Catalog=comsoul1;Integrated Security=True");
            con.Open();
            SqlCommand cmd = new SqlCommand("Select * from comsoul_registration where Fname = '"+txtUser.Text+"' and Password = '"+txtPass.Text+"'", con );
            SqlDataReader reader = cmd.ExecuteReader();
         
            int count = 0;
            while(reader.Read())
            {
                count += 1;
            }
            if (count == 1)
            {
                MessageBox.Show("OK");
                Registraion f2 = new Registraion();
                f2.Show();
            }
            else if(count > 0){
                MessageBox.Show("Doublicate user and Password");
         
            }
            else{
                MessageBox.Show("UserName and Password not correct");
            }

            txtUser.Clear();
            txtPass.Clear();
     }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
     
    }
}



Registraion.cs




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;


namespace user_login
{
    public partial class Registraion : Form
    {
        //C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE

        string path = @"Data Source=ASP4-PC\SQLEXPRESS;Initial Catalog=comsoul1;Integrated Security=True";

        public Registraion()
        {
            InitializeComponent();
        }

        private void btnregister_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(path);
            if (con.State != ConnectionState.Open)
            {
                con.Open();
                string addquery = string.Format("insert into comsoul_registration (Fname,Lname, Phone, Street, Zip_code, Email, Password,Re_enter, Creadit_card,Creadit_card_type,Date_Time) values('" + 
                                                                                        txtFname.Text + "','" + txtLname.Text + "','" + txtPhone.Text + "', '" + txtStreet.Text + "', '" + txtZip.Text + "','" + txtEmail.Text + "','" + txtPassword.Text + "', '" + txtRepassword.Text + "','" + txtCcard.Text + "','" + txtCcard2.Text + "','" + txtdate.Value.Date + "')");

                SqlCommand cmd = new SqlCommand(addquery,con);

                var roweffected = cmd.ExecuteNonQuery();


                MessageBox.Show("Inserted Data !");

                txtFname.Text = null;
                txtLname.Text = null;
                txtPhone.Text = null;
                txtStreet.Text = null;
                txtZip.Text = null;
                txtEmail.Text = null;
                txtPassword.Text = null;
                txtRepassword.Text = null;
                txtCcard.Text = null;
                txtCcard2.Text = null;
              
            }
            else
            {
                con.Close();

            }

        }

        private void btncancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}





database





create  database comsoul1
  
  create table comsoul_registration
  (
id int primary key identity,
[Fname] varchar (50),
[Lname] varchar (50),
[Phone] int,
[Street] varchar (50),
[City] varchar (50),
[Zip_code] int,
[Email] varchar (50),
[Password] varchar (50),
[Re-enter] varchar (50),
[Creadit_card] int,
[Creadit_card_type] varchar (50),
  )
  
  alter table comsoul_registration
  add [Date_Time] datetime
  
  select * from comsoul_registration