Wednesday, November 13, 2013

Create Awesome Loginbox



Create Login.html

<html>
<head>

<title>Loginbox</title>
<link rel="stylesheet" type="text/css" href="login.css">
</head>

<body >
<div id="loginbox">

<form id="login">
    <h1>Log In</h1>
    <fieldset id="inputs">
        <input id="username" type="text" placeholder="Username" autofocus required>
        
        <input id="password" type="password" placeholder="Password" required>
    </fieldset>
    <fieldset id="actions">
        <input type="submit" id="submit" class="orange" value="Log in">
        <p class="reg">
        <a href="">Register</a>
        &nbsp;&nbsp;&nbsp;
        <a class="forget" href="">Forgot your password?</a>
        </p> 
    </fieldset>
</form>

</div>
</body>
</html>

Create Login.css


#loginbox{
 margin-left:auto;
 margin-right:auto;
 position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}
#login
{
    box-shadow:
          0 0 2px rgba(0, 0, 0, 0.2),  
          0 0px 1px rgba(0, 0, 0, .2),
          0 0px 0 #fff,
          0 0px 0 rgba(0, 0, 0, .2),
          0 0px 0 #fff,  
          0 0px 0 rgba(0, 0, 0, .2);
    border:solid #006 5px;
    border-style:ridge;

}
#login
{
 position:relative;
    z-index: 0;
 width:450px;
 height:280px;
 text-align:center;
 margin-left:auto;
 margin-right:auto;
}
#inputs{
 border:none;
}
#inputs input {
 width:400px;
 height:45px;
 border: 2px solid #dadada;
    border-radius: 7px;
 background-color:#F8F8F8;

}
#inputs input:focus { 
    outline: none;
    border-color: #9ecaed;
    box-shadow: 0 0 10px #9ecaed;
 background-color:#FFF;
}
#username{
 padding-left:35px;
 background:url(Places-user-identity-icon.png) left no-repeat;
}
#password{
 margin:15px 0px 0px 0px;
 padding-left:35px;
 background:url(blue_key.png) left no-repeat;
}
#actions{
 border:none;
 margin-left:0px;
}

#submit{
 width:130px;
 height:40px;
 margin-left:-30px;
 margin-top:20px;
}
.orange {
 color: #fef4e9;
 border: solid 1px #da7c0c;
 background: #f78d1d;
 background: -webkit-gradient(linear, left top, left bottom, from(#faa51a), to(#f47a20));
 background: -moz-linear-gradient(top,  #faa51a,  #f47a20);
 filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#faa51a', endColorstr='#f47a20');
 border-radius: 5px;
}
.orange:hover {
 background: #f47c20;
 background: -webkit-gradient(linear, left top, left bottom, from(#f88e11), to(#f06015));
 background: -moz-linear-gradient(top,  #f88e11,  #f06015);
 filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#f88e11', endColorstr='#f06015');
}
.orange:active {
 color: #fcd3a5;
 background: -webkit-gradient(linear, left top, left bottom, from(#f47a20), to(#faa51a));
 background: -moz-linear-gradient(top,  #f47a20,  #faa51a);
 filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#f47a20', endColorstr='#faa51a');
}
.reg{
 float:right;
 text-decoration:none;
 margin-top:30px;
 margin-right:20px;
 text-decoration:none;
}
#login:before
{
    content: '';
    position: absolute;
    z-index: -1;
    border: 1px dashed #ccc;
    top: 5px;
    bottom: 5px;
    left: 5px;
    right: 5px;
    -moz-box-shadow: 0 0 0 1px #fff;
    -webkit-box-shadow: 0 0 0 1px #fff;
    box-shadow: 0 0 0 1px #fff;
}
h1
{
    text-shadow: 0 1px 0 rgba(255, 255, 255, .7), 0px 2px 0 rgba(0, 0, 0, .5);
    text-transform: uppercase;
    text-align: center;
    color: #666;
    margin: 15px 0 30px 0;
    letter-spacing: 4px;
    font: normal 26px/1 Verdana, Helvetica;
    position: relative;
}

h1:after, h1:before
{
    background-color: #777;
    content: "";
    height: 1px;
    position: absolute;
    top: 15px;
    width: 120px;   
}

h1:after
{ 
    background-image: -webkit-gradient(linear, left top, right top, from(#777), to(#fff));
    background-image: -webkit-linear-gradient(left, #777, #fff);
    background-image: -moz-linear-gradient(left, #777, #fff);
    background-image: -ms-linear-gradient(left, #777, #fff);
    background-image: -o-linear-gradient(left, #777, #fff);
    background-image: linear-gradient(left, #777, #fff);      
    right: 0;
}

h1:before
{
    background-image: -webkit-gradient(linear, right top, left top, from(#777), to(#fff));
    background-image: -webkit-linear-gradient(right, #777, #fff);
    background-image: -moz-linear-gradient(right, #777, #fff);
    background-image: -ms-linear-gradient(right, #777, #fff);
    background-image: -o-linear-gradient(right, #777, #fff);
    background-image: linear-gradient(right, #777, #fff);
    left: 0;
}

copy the images in the login.html folder


Tuesday, September 3, 2013

Simple jQuery form validation


Code for Simple jQuery form validation


<!DOCTYPE html>
<html>
<head>

<style type="text/css">
label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
</style>

<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<script language="javascript" type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js"></script>

<script>

$(function() {
   $( "#mytestform" ).validate({
           rules: {
                   aname: {
                           required: true,
                           minlength: 4,
                           maxlength: 20,
                           customvalidation: true
                         },
              lastname: { 
                          required: true,
                           minlength: 4,
                           maxlength: 20,
                           lettersonly: true
                         }
           },
           messages: {
                   aname: {
                           required: "Dude, enter a name",
                           minlength: $.format("Keep typing, at least {0} characters required!"),
                           maxlength: $.format("Whoa! Maximum {0} characters allowed!")
                   }
           }
   });
$.validator.addMethod("customvalidation",
           function(value, element) {
                   return /^[A-Za-z\d=#$%@_ -]+$/.test(value);
           },
   "Sorry, no special characters allowed"
   );

$.validator.addMethod("lettersonly", 
          function(value, element) { 
        return this.optional(element) || /^[a-z]+$/i.test(value); 
          }, 
"Letters only please"
); 

$('.address').each(function() {
    $(this).rules('add', {
        required: true,
        minlength: 5,
        maxlength: 10,
        messages: {
            required: "Required input",
            minlength: "Must be at least {0} characters",
            maxlength: "Must be less than {0} characters"
        }
    });
});

});

</script>
</head>
<body>
<form id="mytestform" name="" method="get"  action="">

Name:
<input name="aname" size="20" />
last Name:
<input name="lastname"/>
adress:
<input name="adress" class="address" />

<input class="submit" type="submit" value="Submit"/>

</form>
</body>
</html>


Demo:




Name:



last Name:



adress:




Friday, July 26, 2013

Display text from database with read more link

Display text from database with read more link

Retrieve data from a table

Address book



1st we create two files list.php, person.php with the following code:

Code for list.php
<html>
 <body>
 <ul>
 <?php
 mysql_connect("localhost", "admin", "abc123") or die (mysql_error ());
 mysql_select_db("mydb") or die(mysql_error());
 $rs = mysql_query('SELECT * FROM mytable');
while($result = mysql_fetch_array($rs)){ 

   echo $result['firstname'];
   echo $result['lastname'];
echo "<a href='person.php?id=".$result['id']."'> More... </a>";
echo"<br>";
}
 mysql_close();
 ?>
 </ul>
 </body>
 </html>
code for person.php
<html>
 <body>
 <dl>
 <?php
 mysql_connect("localhost", "admin", "abc123") or die (mysql_error ());
 mysql_select_db("mydb") or die(mysql_error());
 
 $strSQL = "SELECT * FROM mytable WHERE ID=" . $_GET["id"];
 $rs = mysql_query($strSQL);
 
 // Loop the recordset $rs
 while($row = mysql_fetch_array($rs)) {

  // Write the data of the person
  echo "<dt>Name:</dt><dd>" . $row["firstname"] . " " . $row["lastname"] . "</dd>";
  echo "<dt>Phone:</dt><dd>" . $row["Contactno"] . "</dd>";
  echo "<dt>Birthdate:</dt><dd>" . $row["dateofbirth"] . "</dd>";
 }
 mysql_close();
 ?>
 </dl>
 <p><a href="list.php">Return to the list</a></p>
 </body>
 </html> 

Thursday, May 23, 2013

PHP Login System

Login is a very important part of any website, from securing contents from prying eyes to tracking visitors on your website. This tutorial is a simple login form for a website.
Firstly you create "login.php" like this

Code:
<?php
session_start
();
// This starts the session which is like a cookie,
but it isn't saved on your hdd and is much more secure.
mysql_connect("localhost","DATABASE USER HERE","PASSWORD");
// Connect to the MySQL server
mysql_select_db("login");
 // Select your Database
if(isset($_SESSION['loggedin']))
{
    die(
"You are already logged in!");
 // That bit of code checks if you are logged in or not,
and if you are logged, you can't log in again!
}

if(isset($_POST['submit']))
{
   
$name mysql_real_escape_string($_POST['username']); 
// The function mysql_real_escape_string() stops hackers!
   
   $pass mysql_real_escape_string($_POST['password']); 
   $mysql mysql_query("SELECT * FROM users WHERE name = '{$name}
   AND password = '{$pass}'");

//get all users in the database with that username and password.
   
if(mysql_num_rows($mysql) < 1)
   {
     die(
"Password was probably incorrect!");
   } 
//check number of rows the MySQL query was less than 1,
so if it couldn't find a row, 
the password is incorrect or the user doesn't exist!
   
   $_SESSION['loggedin'] = "YES";
// Set it so the user is logged in!
   $_SESSION['name'] = $name
// Make it so the username can be called by $_SESSION['name']
   die("You are now logged in!"); 
// it doesn't show the login form after you are logged in!

echo "<form type='login.php' method='POST'>
Username: <br>
<input type='text' name='username'><br>
Password: <br>
<input type='password' name='password'><br>
<input type='submit' name='submit' value='Login'>
</form>"
//the form to enter your password and username to login.
?>

After you have put that code, run this query on your database:

Code:

CREATE TABLE `users` (
`id` BIGINT( 60 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 50 ) NOT NULL ,
`password` VARCHAR( 32 ) NOT NULL ,
`date` INT( 32 ) NOT NULL ,
`email` VARCHAR( 80 ) NOT NULL
);

And then add all of the users you wish to the table!
--------------
To integrate this within your site, you can do the following at the top of your site.
This Code Like Lock.php or This Code Using to Lock Your Webpages

Code:
<?php
session_start(); // NEVER forget this!
if(!isset($_SESSION['loggedin']))
{
    die("To access this page, you need to <a href='login.php'>LOGIN</a> "); 

// Make sure they are logged in!
} 
// What the !isset() code does, is check to see if the variable $_SESSION['loggedin'] is there, and if it isn't it kills the script telling the user to log in!
?>

If you want display your user name on your site use this code:
Code
<?php echo "Hello there, {$_SESSION['name']}! Welcome to my site!"; ?>

Logout.php:
Code
<?php
session_start();
if(isset($_SESSION['name']))
  unset($_SESSION['loggedin']);
  header('Location: index.php');
?>
or
<?php
    session_start();
    $_SESSION = array();
    session_destroy();
?>

Tuesday, May 14, 2013

Accessing form elements by name with jQuery

There are a variety of ways to access elements with jQuery including by the name property of form elements (the name="" part of <input name="foo">). This can be useful so you don't have to assign an id to each and every form element as well as a name which is needed to pass the form value to the next page.

Example form

Here's a snippet of a form for the following examples with first_name and last_name fields in a form.

<form ... >
    ....
    <input type="text" name="first_name" value="" />
    <input type="text" name="last_name" value="" />
    ....
</form>

Selecting by name
To select the "first_name" text input form element do this:
$("input[name=first_name]");
For example to display the value in an alert window do this:
alert( $("input[name=first_name]").val() );

Source : http://www.electrictoolbox.com/jquery-form-elements-by-name/

Wednesday, May 8, 2013

jQuery Awesome Datepicker / formatDate

Example : 







<html>
<head>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <script>
$(function() {
    $( "#my_date" ).datepicker({ 
    dateFormat: "MM/dd/yy",
    defaultDate: "January/01/1970",
    minDate: "January/01/1925",
    maxDate: "December/31/2011",
    changeMonth: true,
    changeYear: true,
    yearRange: "1925:2011",
    onClose: function(dateText, inst) {
        var validDate = $.datepicker.formatDate( "MM/dd/yy", $('#my_date').datepicker('getDate'));
            $('#my_date').datepicker('setDate', validDate);
        }
    });
});
  </script>
</head>
<body>
<input name="my_date" id="my_date" type="text" value="January/01/1970" />
</body>
</html>

Tuesday, May 7, 2013

Twitter Style(glow) Textbox Using Css3

<html>
<head>
<style type="text/css">
.inputbox{
border-radius:5px;
-webkit-transition: all 0.30s ease-in-out;
-moz-transition: all 0.30s ease-in-out;
-ms-transition: all 0.30s ease-in-out;
-o-transition: all 0.30s ease-in-out;
outline: none;
padding: 3px 0px 3px 3px;
border: 1px solid #999;
}
.inputbox:focus{
 background-color:#FFF;
 border: 1px solid #07c;
        box-shadow: 0 0 10px #07c;
}
</style>
</head>
<body>
<input name="fname" type="text" class="inputbox" value="twitter">
</body>
</html>

Example :


Monday, May 6, 2013

PHP MySQL Update Using Forms

<DOCTYPE html>
<html>
<head>
</head>
<body>

<?php
$con=mysqli_connect("localhost","abc","abc456","mydb");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

    $newname = mysql_real_escape_string( $_POST["fname"] );

if (isset($_POST['submit'])) {

mysqli_query($con,"UPDATE users SET firstname = '$newname'
WHERE id=3");

header('Location: index.php');
}

mysqli_close($con);

?>

    <form name="profedit" action="" method="post">
    <br>First Name :<input readonly type="text" class="input" name="fname" border="3px" value=" <?php echo"$display"; ?> ">
<br>
<input type="button" id="btnsubmit" value="edit">
<input type="submit" value="Submit" name="submit" id="save" />
<br>
</form>
</body>
</html>

php jquery profile edting

<DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>

$(document).ready(function(){
  $("#save").click(function(){
    $("input").attr("readonly", true);
$("input#input").removeAttr('id');
$(".input").attr('id', 'aftersave');
  });
});

$(document).ready(function(){
  $("#btnsubmit").click(function(){
    $("input").attr("readonly", false);
$(".input").attr('id', 'input');

  });
});
</script>
<style type="text/css">
.input{
border:solid 0px;
}
#input{
border:solid 2px #00F;
}
#aftersave{
border:solid 0px #000;
}

</style>
</head>
<body>

<?php
$con=mysqli_connect("localhost","admin","abc123","mydb");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$result = mysqli_query($con,"SELECT * FROM users");

while($row = mysqli_fetch_array($result))
  {
  $display = $row['firstname'];
  }
  
    $newname = mysql_real_escape_string( $_POST["fname"] );
  
if (isset($_POST['submit'])) {

mysqli_query($con,"UPDATE users SET firstname = '$newname'
WHERE id=3");

header('Location: index.php');
}

mysqli_close($con);

?>

    <form name="profedit" action="" method="post">
    <br>First Name :<input readonly type="text" class="input" name="fname" border="3px" value=" <?php echo"$display"; ?> ">
<br>
<input type="button" id="btnsubmit" value="edit">
<input type="submit" value="Submit" name="submit" id="save" />
<br>
</form>

</body>
</html>


After submit


Retrieve data from a table || Get value from database php

<?php

$con=mysqli_connect("localhost","admin","abc123","mydb");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$result = mysqli_query($con,"SELECT * FROM users");

while($row = mysqli_fetch_array($result))
  {
  $display = $row['firstname'];
  echo"$display";
  }
  
mysqli_close($con);

?>

Thursday, May 2, 2013

Add Remove Attributes - jQuery

Add new id

$(element).attr('id', 'newID');

remove id

<img class="thumb" id="thumb" src="img/1_1.jpg" />

$('img#thumb').removeAttr('id');

Example :

<DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>

$(document).ready(function(){
  $("#save").click(function(){
    $("input").attr("readonly", true);
$("input#input").removeAttr('id');
$(".input").attr('id', 'aftersave');
 });
});

$(document).ready(function(){
  $("#btnsubmit").click(function(){
    $("input").attr("readonly", false);
$(".input").attr('id', 'input');
  });
});
</script>
<style type="text/css">
#input{
border:solid 2px #00F;
}
#aftersave{
border:solid 0px #000;
}
#save{
background:#CFC;
}
</style>
</head>
<body>
<p>Simple button function</p>

<input readonly type="text" class="input" name="Language" border="3px" value="English">
<br>
<input type="button" id="btnsubmit" value="edit">
<input type="button" id="save" value="save">
</body>
</html>

Tuesday, April 30, 2013

Submitting a date to Database from datepicker || PHP mysql insert date format



$date = mysql_real_escape_string($_POST['date']);
$new_date = date('Y-m-d',strtotime($date));

$sql="INSERT INTO some_table (date)
VALUES
('$new_date')";

Example 2 

//get the correct format
$new_date = date('Y-m-d',strtotime($_POST['date']));

//then you can insert that date

$insert = 'INSERT INTO some_table (field1) VALUES("'.mysql_real_escape_string($new_date).'")';

Tuesday, April 23, 2013

php check if record already exists




<?php

mysql_connect('localhost', 'admin', 'abc456');
mysql_select_db('web');
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?>
<?php

$suid = $_SESSION['userid'];
$check = mysql_query("SELECT id FROM arts WHERE id = '$suid'");
$chid = mysql_fetch_array( $check );

if ($chid == true)
   {
  header('Location: userprofile.php');
   }
  else {
 header('Location: edit-profile.php');
       }
?>

Monday, April 22, 2013

jquery ajax form submit loading image

1. Insert this code below head tag

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
</script>

2. And Form code change like this

<form action="" method="post" name="register">
<input name="submit" type="submit" value="register" style="width:100px;" onclick="$('#loading').show();">
</form>
<div id="loading" style="display:none;"><img src="ajax_progress2.gif" alt="" /></div>

Example:

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
</script>
</head>
<body>
<br>
<form action="" method="post" name="register">
<label>username:</label><input name="name" type="text"><br>
<label>password:</label><input name="password" type="password"><br>
<label>email:</label><input name="email" type="text"><br>
<input name="submit" type="submit" value="register" style="width:100px;" onclick="$('#loading').show();">
</form>
<div id="loading" style="display:none;"><img src="ajax_progress2.gif" alt="" /></div>
</body>
</html>

Ajax loader images