Friday, October 28, 2016

Simple Form Validation Using JQuery

///////////////////////////////////////////////////////////////////////////////////////////////////
//// index.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<?php
session_start();
include("connect.php");
if(isset($_COOKIE['username'])) {
$username =$_COOKIE['username'];
}
else {
$username = '';
}
if(isset($_COOKIE['password'])) {
$password =$_COOKIE['password'];
}
else {
$password ='';
}
if(isset($_COOKIE['rememberme'])) {
$rememberme =$_COOKIE['rememberme'];
}
else {
$rememberme ='';
}
if(isset($_REQUEST['action'])) {
$loginSql = "SELECT * FROM login WHERE login_name='".mysql_real_escape_string($_REQUEST['username'])."' AND
login_password='".mysql_real_escape_string($_REQUEST['password'])."'";

$loginquery = mysql_query($loginSql) or die(mysql_error()) ;
if(mysql_num_rows($loginquery)<=0){
$msg = '<font color=#FF0000>Invalid login</font>';;
}
else {
if(isset($_REQUEST['rememberme'])) {
setcookie("username",$_REQUEST['username'],time()*3600); //it is in sec
setcookie("password",$_REQUEST['password'],time()*3600);
setcookie("rememberme",$_REQUEST['rememberme'],time()*3600);//// creates a cookie of name rememberme for 1 hour/////
}
else {
setcookie('username','');  //means you are deleting a cookie
setcookie('password','');
setcookie('rememberme','');/////sysntax for deleting a cookie////
}
$loginArr = mysql_fetch_array($loginquery);
$userId = $loginArr['login_id'];
$_SESSION['usrerid'] = $userId;
$_SESSION['username'] = $loginArr['login_name'];
header("location:index.php");
exit();
}
}
if(isset($_REQUEST['logout'])) {
unset($_SESSION['usrerid']) ;
unset($_SESSION['username']) ;
header("location:login.php");
}



?>
<script src="jquery-1.10.1.js"></script>
<script>
    $(document).ready(function() {
$('#login').attr('onsubmit','return chkValidate()') ;
//$('#usernamr').attr('readonly','readonly')
$('#login').attr('onsubmit','return chkValidate()');

});
function chkValidate() {
var usernamr = $('#usernamr').val();
var password = $('#password').val();
var err = 0;
var msg = '';
if(usernamr == '') {
err++;
msg = msg+'<li>Enter Uename</li>';
}
if(password == '') {
err++;
msg = msg+'<li>Enter password</li>';
}
if(err>0){
$('#msg').html(msg);
if(document.getElementById("errormsg").style.display == "none") {
$("#errormsg").toggle();
}
return false;
}
else {
return true;
}
}


</script>







<h3 align="center">Enter Your login details</h3>
<form method="POST" action="#" id="login" >
<table align="center">
<tr><td>Username</td><td><input type="text" name="username" id="usernamr" value="<?php echo $username ;?>"></td></tr>
<tr><td>Password</td><td><input type="password" name="password" id="password" value="<?php echo $password ;?>"></td></tr>
<tr><td>Remember Me</td><td><input type="checkbox" name="rememberme" id="rememberme" value="Y" <?php if($rememberme == 'Y') { ?> checked="checked"<?php } ?>></td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value="Submit" id="formlogin">
<input type="hidden" name="action" value="Trans">
<?php
if(isset($msg)) {
echo $msg ;
}
?>
<span id="errormsg" style="display:none">

<table align="center" cellpadding="1" cellspacing="0" width="75%" border="2" style="border:thick" bgcolor="#999999">
<tr>
<td><span id="msg" style="color:#ff0000;"></td>


</tr>
</table>
</span>
</span>



</td></tr>
</table>
</form>
///////////////////////////////////////////////////////////////////////////////////////////////////
//// End index.php
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//// connect.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<?php

class connect{
   function dbconnect(){
   $con=mysql_connect($this->hostname,$this->username,$this->password);
   mysql_select_db($this->dbname,$con) or die(mysql_error());
      }



}
  $obj=new connect;
  $obj->hostname="localhost";
  $obj->username="root";
  $obj->password="";
  $obj->dbname="pmsd";
  $obj->dbconnect();



?>
///////////////////////////////////////////////////////////////////////////////////////////////////
//// End connect.php
///////////////////////////////////////////////////////////////////////////////////////////////////

Wednesday, October 19, 2016

Autocomplete Using Jquery


///////////////////////////////////////////////////////////////////////////////////////////////////
//// index.php
///////////////////////////////////////////////////////////////////////////////////////////////////

 <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<script>
 $(function(){
   var availableTags = [
    {
    label: "Sao Paulo",
    value: "SP"},
    {
    label: "Sorocaba",
    value: "SO"},
    {
    label: "Paulinia",
    value: "PA"},
    {
    label: "São Roque",
    value: "SR"}
   ];
$("#txtCidade").autocomplete({
    source: availableTags,
    select: function(event, ui) {
        $("#hidCidade").val(ui.item.label);
    }
});
 });
</script>


        <form>
            <input id="hidCidade" type="hidden" />
            <input id="txtCidade" type="input" class="ui-autocomplete-input" />
        </form>
///////////////////////////////////////////////////////////////////////////////////////////////////
//// End index.php
///////////////////////////////////////////////////////////////////////////////////////////////////

Pagination using JQuery and php

///////////////////////////////////////////////////////////////////////////////////////////////////
//// index.php
///////////////////////////////////////////////////////////////////////////////////////////////////


<?php
$Limit=10;
$setLimit=0;
include("db.php");
$dbObj=new DB;
$sql="select * from category limit $setLimit,$Limit";
$results=$dbObj->GetSqlTable($sql);

$countsql="select * from category";
$numrow=$dbObj->GetSqlTable($countsql);
 $numRow=count($numrow);//183
 $numPage=ceil($numRow/$Limit);//19
//echo'<pre>';print_r($results);

?>
Show<select onchange="loadPagi(this.value)" align="left" id="loadppagi">
<?php for($i=10; $i<=100; $i+=10){?>
<option value="<?php echo $i ?>"><?php echo $i ?></option>
<?php }?>

</select>Entries



<h3 align="center" style="color:#FF0066">Muna Pagination</h3>
<div id="displayTable">
<table align="center" border="1" cellpadding="1" style="background-color:#CCFF33" width="60%">
<tr>
<th>ID</th>
<th>Category Name</th>
<th>Category Order</th>
<th colspan="2">Action</th>
</tr>
<?php foreach($results as $result){?>
<tr>
<td><?php echo $result['id']; ?></td>
<td><?php echo $result['cat_name']; ?></td>
<td><?php echo $result['category_order']; ?></td>
<td>Edit</td>
<td>Delete</td>
</tr>
<?php }?>
</table>

<div align="center">

<?php for($i=1; $i<=$numPage;$i++){?>
<button "javascript:void(0)" onclick="midPages(<?php echo $i?>)" style="background-color:#FF99FF"><?php echo $i?></button>
<?php }?>
<button "javascript:void(0)" onclick="nextPages(1)" style="background-color:#CC33FF">Next</button>
</div>
</div>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script>
   function onPage(p){
     alert(p);
 var limit=$("#loadppagi").val();
      $.ajax({
      type:"POST",
 url:"middle.php",
 data:{"limit":limit,"pageno":p},
 success:function(data){
   $("#displayTable").html(data);
 }
     });
   }
  function firstPages(f){
 
 var limit=$("#loadppagi").val();
alert(f);
     $.ajax({
 type:"POST",
 url:"middle.php",
 data:{"pageno":f,"limit":limit},
 success:function(data){
    $("#displayTable").html(data);
 }
 });
 
  }

   function lastPages(l){
 
 var limit=$("#loadppagi").val();
//alert(f);
     $.ajax({
 type:"POST",
 url:"middle.php",
 data:{"pageno":l,"limit":limit},
 success:function(data){
    $("#displayTable").html(data);
 }
 });
 
  }
   function nextPages(n){
   
      n++;
 alert(n);
 var limit=$("#loadppagi").val();
//alert(limit);
     $.ajax({
 type:"POST",
 url:"middle.php",
 data:{"pageno":n,"limit":limit},
 success:function(data){
    $("#displayTable").html(data);
 }
 });
 
   }
   function prevPages(p){
     alert(p);
p--;
 var limit=$("#loadppagi").val();
//alert(limit);
     $.ajax({
 type:"POST",
 url:"middle.php",
 data:{"pageno":p,"limit":limit},
 success:function(data){
    $("#displayTable").html(data);
 }
 });
 
   }
   function midPages(i){
     var limit=$("#loadppagi").val();
alert(limit);
     $.ajax({
 type:"POST",
 url:"middle.php",
 data:{"pageno":i,"limit":limit},
 success:function(data){
    $("#displayTable").html(data);
 }
 });
   }
 
   function loadPagi(t){
   var pageno=1;
   alert(pageno);
   $.ajax({
      type:"POST",
 url:"middle.php",
 data:{"limit":t,"pageno":pageno},
 success:function(data){
   $("#displayTable").html(data);
 }
 
   });

   }
</script>

///////////////////////////////////////////////////////////////////////////////////////////////////
//// End index.php
///////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////
//// fetchmiddle.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<?php




if(isset($_REQUEST['limit'])){
   $Limit=$_REQUEST['limit'];
}
else {$Limit=10;}

if(isset($_REQUEST['pageno'])){
  $pageno=$_REQUEST['pageno'];
  $setLimit=($pageno-1)*$Limit;
}
else{$setLimit=0;}
include("db.php");
$dbObj=new DB;
$sql="select * from category limit $setLimit,$Limit";
$results=$dbObj->GetSqlTable($sql);

$countsql="select * from category";
$numrow=$dbObj->GetSqlTable($countsql);
 $numRow=count($numrow);//183
 $numPage=ceil($numRow/$Limit);//19


?>
     <table align="center" border="1" cellpadding="1" style="background-color:#FFCCFF" width="60%">
<tr>
<th>ID</th>
<th>Category Name</th>
<th>Category Order</th>
<th colspan="2">Action</th>
</tr>
<?php foreach($results as $result){?>
<tr>
<td><?php echo $result['id']; ?></td>
<td><?php echo $result['cat_name']; ?></td>
<td><?php echo $result['category_order']; ?></td>
<td>Edit</td>
<td>Delete</td>
</tr>
<?php }?>
</table>      
             
                <div align="center">
<button "javascript:void(0)" onclick="firstPages(1)" style="background-color:#CC33FF">First</button>
<?php if($pageno>1){?>
<button "javascript:void(0)" onclick="prevPages(<?php echo $pageno?>)" style="background-color:#CC33FF">Prev</button>
<?php } ?>
<?php for($i=1; $i<=$numPage;$i++){?>
<button "javascript:void(0)" onclick="midPages(<?php echo $i?>);" style="background-color:#FF99FF"><?php if($i==$pageno){?> <font style="color:#FF0000" style="background-color:#FF9900"><strong><?php }?> <?php echo $i?></strong></font></button>
<?php }?>
 <?php if($pageno<$numPage){?>
<button "javascript:void(0)" onclick="nextPages(<?php echo $pageno?>)" style="background-color:#CC33FF">Next</button>
 <?php } ?>
<button "javascript:void(0)" onclick="lastPages(<?php echo $numPage?>)" style="background-color:#CC33FF">Last</button>
Page
   <select onchange="onPage(this.value)" align="left" id="onPage">
<?php for($i=1; $i<=$numPage;$i++){?>
<option value="<?php echo $i ?>"><?php echo $i ?></option>
<?php }?>

</select>
<br/>Showing Page: <?php echo $pageno?> of <?php echo $numPage?>
</div>
</div>
///////////////////////////////////////////////////////////////////////////////////////////////////
//// End fetchmiddle.php
///////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////
//// db.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<?php
///////////////////////////////////////////////////////////////////////////////////////////////////
//// Muna  Database Function Library
///////////////////////////////////////////////////////////////////////////////////////////////////
//// Database Functions
///////////////////////////////////////////////////////////////////////////////////////////////////
////
//// Usage:
//// $db = new DB(); //instantiate using default read-only connection
//// $db = new DB($user,$pass); //instantiate using a specific login/pass
////
///////////////////////////////////////////////////////////////////////////////////////////////////

$showsql = true;
//$db = new DB();

class DB {
  private $dbhost = "localhost";
  private $dbuser = "root";
  private $dbpass = "";
  private $dbname = "ecommerce";

  public $error = "";

  function __construct()
    {
    }

//---------------
//foreach ($customers as $customer) {
//    $row[0]=$customer->cust_name;
//    $row[1]=$customer->monthly_income;
//    array_push($rows,$row);
//}
//print json_encode($rows, JSON_NUMERIC_CHECK);
//---------------
public function ReportError ($sql, $message) {
//echo "SQL ERROR:\nMessage: $message\nSQL: $sql\n";
$this->error = $message;
}

//highchart
public function GetChart ($sql)
    {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
$rows = Array();
    while ($res = mysql_fetch_object($result)) //will ignore anything that comes after
{
    $row[0]=$res->year;
             $row[1]=$res->amount;
//$row[1]=$channel->Date;
             array_push($rows,$row); //array_push(array,value1,value2...)

}
    mysql_close($con);
//print_r($rows);
    print_r(json_encode($rows, JSON_NUMERIC_CHECK));
    }
//delete by muna

public function deleteRow($sql) {
$con = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass);
if (!$con) {
die("Could not connect to database!");
}
mysql_select_db($this->dbname, $con);
//mysql_select_db("esigns_prod", $con);
$result = mysql_query($sql, $con);
mysql_close($con);
return $result;
}
//by muna
public function GetSqlTable ($sql)
    {
    $data = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
    while ($row = mysql_fetch_array($result)) //will ignore anything that comes after
{
$data[] = $row;
}
    mysql_close($con);
    return $data;
    }

public function InsertSql ($sql)
    {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result) {$output= 1;}
else $output= 0;
 
    mysql_close($con);
    return $output;
    }


//returns a 1d list of results (using the first column returned)
public function GetList2 ($sql) {
$con = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass);
if (!$con) {
die("Could not connect to database!");
}
//mysql_select_db("esigns_prod", $con);
$result = mysql_query($sql, $con);
while ($row = mysql_fetch_array($result)) {
$results[] = $row[0];
}
mysql_close($con);
return $results;
}



public function GetRow2 ($sql) {
$con = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass);
if (!$con) {
die("Could not connect to database!");
}
//mysql_select_db($this->dbname, $con);
mysql_select_db("esigns_prod", $con);
$result = mysql_query($sql, $con);
//echo $sql;
//var_dump($result);
//echo mysql_error($con);
//mysql_close($con);
return mysql_fetch_assoc($result);
}


  public function GetDB ()
    {
    $con = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass);
    if (!$con)
          {
          die("Could not connect to database!");
          }
    mysql_select_db($this->dbname, $con);
    return $con;
    }


  public function Clean($sql)
         {
         return mysql_real_escape_string($sql, $this->GetDB());
         }


  public function Query ($sql)
    {
    $output=0;
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if (!isset($result))
          {
          return 0;
          }
    if (!$result) {return 0;}
    if ($row = mysql_fetch_row($result))
      {
        $output = $row[0];
      }
    mysql_close($con);
    return $output;
    }

  //returns the first two columns in an sql query as a keyed array
  public function GetArray ($sql)
        {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
    while ($row = mysql_fetch_row($result))
      {
                //verify there are two rows of data, otherwise return an indexed list of the first
            $output[$row[0]] = $row[1];
      }
    mysql_close($con);
    return $output;
        }
  //returns the first column of each row returned
  public function GetList ($sql)
        {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
    while ($row = mysql_fetch_row($result))
      {
            array_push($output, $row[0]);
      }
    mysql_close($con);
    return $output;
        }


  public function GetResult ($sql)
    {
    $con = $this->GetDB();
    if (!$con) {return 0;}
    $result = mysql_query($sql, $con);
    //mysql_close($con);
    return $result;
    }


public function GetJSON ($sql)
    {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
    while ($row = mysql_fetch_row($result)) //will ignore anything that comes after
{
$data = Array();
for ($i=0; $i<mysql_num_fields($result);  $i++) {
$data[mysql_fetch_field($result, $i)->name] = $row[$i];
}
array_push($output, $data);
}
    mysql_close($con);
    return json_encode($output);
    }

public function GetTable ($sql)
    {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
    while ($row = mysql_fetch_row($result)) //will ignore anything that comes after
{
$data = Array();
for ($i=0; $i<mysql_num_fields($result);  $i++) {
$data[mysql_fetch_field($result, $i)->name] = $row[$i];
}
array_push($output, $data);
}
    mysql_close($con);
    return $output;
    }








  public function GetRow ($sql)
    {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
    if ($row = mysql_fetch_row($result)) //will ignore anything that comes after
      {
                $output = $row;
      }
    mysql_close($con);
    return $output;
    }

  public function GetRowObject ($sql)
    {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
    if ($row = mysql_fetch_assoc($result)) //will ignore anything that comes after
      {
                $output = $row;
      }
    mysql_close($con);
    return $output;
    }


  public function GetRows ($sql)
    {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
    while ($row = mysql_fetch_row($result)) //will ignore anything that comes after
      {
array_push($output, $row);
      }
    mysql_close($con);
    return $output;
    }


  public function Command ($sql)
    {
global $showsql;
$this->error = "";
//if ($showsql) {echo "SQL: $sql\n";}
    $con = $this->GetDB();
    if (!$con) {return 0;}
    $result = mysql_query($sql, $con);
    $rows = mysql_affected_rows($con);
        if ($rows < 1)
          {
 $this->error = mysql_error($con);
 //$this->ReportError($sql, mysql_error($con));
          //echo "DB ERROR: " . mysql_error($con) . "\n";
          }
    mysql_close($con);
    return $rows;
    }





}
?>



///////////////////////////////////////////////////////////////////////////////////////////////////
//// End db.php
///////////////////////////////////////////////////////////////////////////////////////////////////

Tuesday, October 18, 2016

Add a new Row on OnClick Using JavaScript

///////////////////////////////////////////////////////////////////////////////////////////////////
//// index.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>


</head>

<script language="javascript" type="text/javascript">

    function addField() {
    var tbody = document.getElementById("tblBody");
    var ctr = tbody.getElementsByTagName("input").length + 1;
    var input;
 
    if ( ctr > 15 ) {
          alert ("If you want to tell the whole world, dont do it all at once please");
    }else{
 
        if (document.all){ //input.name doesn't work in IE
            input = document.createElement('<input name="field_'+ctr+'">');
        }else{
            input = document.createElement('input');
            input.name = "field_"+ctr;
        }

        input.id = input.name;
        input.type = "text";
        input.value = "";
        input.className = "textfield";
        var cell = document.createElement('td');
        cell.style.height = '30px';
        cell.appendChild(document.createTextNode(ctr+". "));
        cell.appendChild(input);
        var row = document.createElement('tr');
        row.appendChild(cell);
        tbody.appendChild(row);
 
        window.document.the_form.count.value = ctr;
 
    }
}
</script>



<body>




    <form name="the_form" id="the_form" method="post" action="">
   
          <table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tbody id="tblBody">
            <tr>
              <td height="30">
                1. <input name="field_1" type="text" class="textfield" id="field_1" />
              </td>
            </tr>
            <tr>
              <td height="30">
                2. <input name="field_2" type="text" class="textfield" id="field_2" />
              </td>
            </tr>
            <tr>
              <td height="30">
                3. <input name="field_3" type="text" class="textfield" id="field_3" />
              </td>
            </tr>
            <tr>
              <td height="30">
                4. <input name="field_4" type="text" class="textfield" id="field_4" />
              </td>
            </tr>
           
        <tbody
        </table>
          <input name="count" type="hidden" id="count" value="4"/>      
          <input name="add" type="button" class="button" id="add" value="Add Another" onClick="addField();"/>        

    </form>
   

</body>
</html>
///////////////////////////////////////////////////////////////////////////////////////////////////
//// End index.php
///////////////////////////////////////////////////////////////////////////////////////////////////


Sunday, October 16, 2016

Stop the default action of an element using event.preventDefault()

///////////////////////////////////////////////////////////////////////////////////////////////////
//// index.php
///////////////////////////////////////////////////////////////////////////////////////////////////



        <form method="post" action="#">
        <div class="col-md-5">
        <input type="text" name="startdate" id="startdate" class="form-control datepicker">
        <span class="error" id="date-error_strtdt"></span></div>
        <div class="col-md-5">
        <input type="text" name="enddate" id="enddate" class="form-control datepicker">
        <span class="error" id="date-error"></span></div>
        <button class="btn btn-default" id="submitButton" name="submitButton"><i class="fa fa-sort"></i> Submit</button>
        </form>

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
$("#submitButton").on('click', function () {

alert( $( "#startdate" ).val().length);
alert( $( "#enddate" ).val().length==0);


    if ( ($( "#startdate" ).val().length == 0 ) && ($( "#enddate" ).val().length != 0 )) {
    $("#date-error_strtdt").html("Please Select the Start Date");
    event.preventDefault();
    }
    if (( $( "#enddate" ).val().length == 0 ) && $( "#startdate" ).val().length != 0 ) {
    $("#date-error").html("Please Select the End date");
    event.preventDefault();
    }
    else {
//alert("got both");
}
});
</script>
<?php
 if(isset($_REQUEST['submitButton'])){
 echo("comming here");
 }
?>
///////////////////////////////////////////////////////////////////////////////////////////////////
//// End index.php
///////////////////////////////////////////////////////////////////////////////////////////////////

Monday, October 10, 2016

Form Replication on Onclick using JQuery

<?php

session_start();

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


$_SESSION['success'] = 1;

if($_POST['personal']['name'] == ''){
$_SESSION['msg'][] = "Name can't be empty";
$_SESSION['success'] = 0;
}

if($_POST['personal']['email']==''){
$_SESSION['msg'][] = "Email can't be empty";
$_SESSION['success'] = 0;
}


if($_SESSION['success'] == 1) {
header('Location:confirmation.php');
}
else {
if(is_array($_SESSION['msg']) && count($_SESSION['msg'])) {
foreach($_SESSION['msg'] as $msg) {
$string .= $msg.'<br />';
unset($_SESSION['msg']);
}
}
}
}
?>
<html>
<head>
<title>Registration</title>


<style>
.left
{ float: left;
  width: auto;
  margin-right: 10px;}

.right
{ float: right;
  width: auto;
  margin-left: 10px;}

.form_settings
{ margin: 15px 0 0 0;}

.form_settings p
{ padding: 0 0 4px 0;}

.form_settings span
{ float: left;
  width: 200px;
  text-align: left;}

.form_settings input, .form_settings textarea
{ padding: 5px;
  width: 299px;
  font: 100% arial;
  border: 1px solid #E5E5DB;
  background: #FFF;
  color: #47433F;}

.form_settings .submit
{ font: 100% arial;
  border: 1px solid;
  width: 99px;
  margin: 0 0 0 212px;
  height: 33px;
  padding: 2px 0 3px 0;
  cursor: pointer;
  background: #263C56;
  color: #FFF;}

.form_settings textarea, .form_settings select
{ font: 100% arial;
  width: 299px;}

.form_settings .submit
{ font: 100% arial;
  border: 1px solid;
  width: 99px;
  margin: 0 0 0 428px;
  height: 33px;
  padding: 2px 0 3px 0;
  cursor: pointer;
  background: #263C56;
  color: #FFF;}


</style>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
var i=1;
$(document).ready(function(){
$('#addMore').click( function(){
i++;
$('#qualification').append('<fieldset class="form_settings" style="width:380px;"><legend>Qualification '+i+'</legend><p><span>Name of Examination: </span><input type="text" name="educational['+i+'][exam]" ></p><p><span>School: </span><input type="text" name="educational['+i+'][school]"></p><p><span>Year of Passing: </span><input type="text" name="educational['+i+'][year]"></p></fieldset>');
});
});
</script></head>

<body>
<form name="form_register" method="post" action="register.php" align="center">
<?php echo $string;  ?>
<fieldset class="form_settings" style="width:580px;">
<legend>Personal Information</legend>
<p><span>Name: </span><input type="text" name="personal[name]"></p>
<p><span>Address: </span>
  <input type="text" name="personal[address]">
</p>
<p><span>Phone: </span><input type="text" name="personal[phone]"></p>
<p><span>Email: </span><input type="text" name="personal[email]"></p>

</fieldset>
<fieldset class="form_settings" style="width:580px;">
<legend>Educational Information</legend>
<input type="button" class="submit" value="Add Another" name="addMore" id="addMore"/>

<div id="qualification">
<fieldset class="form_settings" style="width:380px;">
<legend>Qualification 1</legend>
<p><span>Name of Examination: </span><input type="text" name="educational[0][exam]" ></p>
<p><span>School: </span><input type="text" name="educational[0][school]"></p>
<p><span>Year of Passing: </span><input type="text" name="educational[0][year]"></p>
</fieldset>

</div>


</fieldset>
<input type="submit" name="submit" value="Submit">

</form>

</body>
</html>




Wednesday, October 5, 2016

Form Replication with Radio Button Checked.

///////////////////////////////////////////////////////////////////////////////////////////////////
//// index.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<html>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
var i=1;
function g()
{


if(i<11){

$('#qualification').append('<table><tr><td valign="top">Type</td><td valign="top"><input type="radio" name="type_question['+i+']" value="general" checked>General <br/><input type="radio" name="type_question['+i+']" value="specific" >Specific</td> <td class="field1" colspan="3"><textarea name="typeQuestion1['+i+']" id="typeQuestion1" rows="3" cols="58"></textarea></td></tr></table>');

i=i+1;
}
else{
alert("You cannot add more than 10 qualifications");
}
}
 //$(document).ready(function(){
 function addmore(field){
 //$('#addMore').click(function(){
var n = field.length;
//var n = field.length;
////alert(n);
////alert(field);
//var textvalue = document.forms[FormName].elements[FieldName];
g();
// });
 }

</script>

<body>
<form name="formedu" action="submit.php" method="post">
<table>
   <tr>
   <td valign="top">Type</td>
   <td valign="top">
    <input type="radio" name="type_question[0]" value="general" checked>General <br/>
    <input type="radio" name="type_question[0]" value="specific" >Specific
   </td>
   <td class="field1" colspan="3"><textarea name="typeQuestion1[0]" id="typeQuestion1" rows='3' cols='58'></textarea></td>
   </tr>
   <tr>  
   <td class="field1" align="left" ><input type="button" id="addMore" value="ADD" onClick="addmore(document.formedu.typeQuestion1)"></input></td>

   </tr>
 
   <div id="qualification" name="qualification"></div>
   </table>
   <input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
///////////////////////////////////////////////////////////////////////////////////////////////////
//// End index.php
///////////////////////////////////////////////////////////////////////////////////////////////////




Tuesday, October 4, 2016

Dynamically shorten and Expand the Text

///////////////////////////////////////////////////////////////////////////////////////////////////
//// index.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<script>
function abc(){
var lngdscp=document.getElementById("discplg").innerHTML;
var stdscp=document.getElementById("discpst").innerHTML;
var anchor = document.getElementsByTagName("a");
var x = anchor[0].innerHTML;
alert(x);
  if(x=="More&gt;&gt;"){
    alert("greater");
  var x = anchor[0].innerHTML="Less&lt;&lt;";
  document.getElementById("discp").innerHTML=lngdscp;

  }
  else{
     var x = anchor[0].innerHTML="More&gt;&gt;";
 document.getElementById("discp").innerHTML=stdscp;
  }



  alert(lngdscp);
}
</script>

<?php
$description='How High Would You Draft Marcus Mariota ? First Take Today - Thursday - April 30 2015 | Skip Bayless & Stephen A. Smith 4-30-15 Live on Floyd Mayweather vs Manny Pacquiao - Saturday, May 2 at the MGM Grand Garden Arena in Las Vegas, Nev. Watch First Take on Facebook : http://goo.gl/uQM5uD ESPN First Take Full | First Take | Skip Bayless & Stephen A. Smith "ESPN First Take" "First Take" "Skip Bayless" "Stephen A. Smith" First Take - Skip Bayless and Stephen A. Smith discuss First Take News, Videos, Photos, and PodCasts - ESPN First Take - ESPN Topics - ESPN 2 - ESPN.com First Take is an American morning sports talk program on ESPN2 and ESPN2HD. Two back-to-back two-hour episodes air each weekday from Monday through Friday, with the live episode airing from 10 a.m. ET until noon, followed by a repeat. Facebook : https://www.facebook.com/FirstTake Follow us on twitter - http://twitter.com/espn_firsttake "ESPN First Take" "First Take" "Skip Bayless" "Stephen A. Smith" "espn 1st take" "1st take"';

$myarray=array();
$myarray=explode(" ",$description);
echo '<pre>';
$st="";
for($i=0;$i<10;$i++){
$st.=$myarray[$i];
$st.=" ";
}
echo "<table>";
echo "<tr><td width='500'><strong><font color=red>Description:</font></strong><div id='discp'>".$st."</div><a href='javascript:void(0)' onclick='abc()'>More>></a></div></td></tr>";
echo "</table>";


?>

<div id="discplg" style="display:none">
 <?php echo $description;?>
</div>
<div id="discpst" style="display:none">
 <?php echo $st;?>
</div>

///////////////////////////////////////////////////////////////////////////////////////////////////
//// End index.php
///////////////////////////////////////////////////////////////////////////////////////////////////

Saturday, October 1, 2016

Multiple Image Upload with Thumb Creation

///////////////////////////////////////////////////////////////////////////////////////////////////
//// index.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<script>
function displayfun(){
var imgno=document.getElementById('imgno').value;
for(var i=1; i<=imgno; i++){
var display=display+'<br><input type=file name=phot_'+i+' name=phot_'+i+'>';
document.getElementById('displayarea').innerHTML=display;

    }
}
</script>

<form name="f1" action="<?php $_SERVER['URI_REQUEST'];?>" enctype="multipart/form-data" method="post">
<input type="text" name="imgno" id="imgno" />
<input type="button" value="Create Upload Button"  onclick="displayfun()"/>
<span id="displayarea"></span>
<input type="submit" name="sub" value="Enter" />
</form>



<?php
if(isset($_REQUEST['sub']))
{
$path='uploaded/';
$imgno=$_REQUEST['imgno'];
for($i=1; $i<=$imgno; $i++){
if(move_uploaded_file($_FILES['phot_'.$i]['tmp_name'],$path.$_FILES['phot_'.$i]['name'])){
   $sourcePath = 'uploaded/';
$sourceName = $_FILES['phot_'.$i]['name'];


$thumbPath = $sourcePath . 'thumbs/';
$thumbName = $sourceName;
$thumbWidth = 60;

$sourceImage = imagecreatefromjpeg("$sourcePath/$sourceName");
$sourceWidth = imagesx($sourceImage);
$sourceHeight = imagesy($sourceImage);


$targetImage = imagecreate($thumbWidth,$thumbWidth);
imagecopyresized($targetImage,$sourceImage,0,0,0,0,$thumbWidth,
$thumbWidth,imagesx($sourceImage),imagesy($sourceImage));
imagejpeg($targetImage, "$thumbPath/$thumbName");

echo "Image uploaded and thumb created successfully";
?>
<img src="uploaded/<?php echo $_FILES['phot_'.$i]['name'] ;?>" >
<br>
<?php
}
else{
echo "Failed to upload file and create thumb";
}





}
}

?>

///////////////////////////////////////////////////////////////////////////////////////////////////
//// End index.php
///////////////////////////////////////////////////////////////////////////////////////////////////