Friday, 8 November 2019

current time display by java script code

current time display by java script code



<html>

<head>
<title>JS 2</title>
<script language="javascript">
function starttime()
{
var total=new Date();
var h=total.getHours();
var m=total.getMinutes();
var s=total.getSeconds();
m=checktime(m);
s=checktime(s);
document.getElementById("txt1").value=h+":"+m+":"+s;
var t1=setTimeout('starttime()',50);
}
function checktime(i)
{
if(i<10)
{
i="0"+i;
}
return i;
}

</script>
</head>
<body onload="starttime()">
Current System Time : <input type=text id=txt1>
</body>
</html>

Saturday, 2 November 2019

simple pagination coding in php with mysql


container.php


</head>
<body class="">
<div role="navigation" class="navbar navbar-default navbar-static-top">
      <div class="container">
        <div class="navbar-header">
          <button data-target=".navbar-collapse" data-toggle="collapse" class="navbar-toggle" type="button">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a href="http://www.phpzag.com" class="navbar-brand">PHPZAG.COM</a>
        </div>
        <div class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="http://www.phpzag.com">Home</a></li>
          
          </ul>
        
        </div><!--/.nav-collapse -->
      </div>
    </div>
   
    <div class="container" style="min-height:500px;">
    <div class=''>
    </div>


db_connect.php


<?php
/* Database connection start */
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "phpzag_demos";
$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
?>





footer.php

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



header.php

 





<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<!-- jQuery -->


index.php

<?php
include('header.php');
?>
<title>phpzag.com : Demo Create Simple Pagination with PHP and MySQL</title>
<?php include('container.php');?>
<div class="container">
    <h2>Simple Pagination with PHP and MySQL</h2>       
    <?php
    include_once("db_connect.php");
    $showRecordPerPage = 5;
    if(isset($_GET['page']) && !empty($_GET['page'])){
        $currentPage = $_GET['page'];
    }else{
        $currentPage = 1;
    }
    $startFrom = ($currentPage * $showRecordPerPage) - $showRecordPerPage;
    $totalEmpSQL = "SELECT * FROM employee";
    $allEmpResult = mysqli_query($conn, $totalEmpSQL);
    $totalEmployee = mysqli_num_rows($allEmpResult);
    $lastPage = ceil($totalEmployee/$showRecordPerPage);
    $firstPage = 1;
    $nextPage = $currentPage + 1;
    $previousPage = $currentPage - 1;
    $empSQL = "SELECT id,employee_name, employee_salary
    FROM `employee` LIMIT $startFrom, $showRecordPerPage";
    $empResult = mysqli_query($conn, $empSQL);       
    ?>   
    <table class="table ">
    <thead>
        <tr>
            <th>EmpID</th>
            <th>Name</th>
            <th>Salary</th>
        </tr>
    </thead>
    <tbody>
        <?php
        while($emp = mysqli_fetch_assoc($empResult)){
        ?>
            <tr>
                <th scope="row"><?php echo $emp['id']; ?></th>
                <td><?php echo $emp['employee_name']; ?></td>
                <td><?php echo $emp['employee_salary']; ?></td>
            </tr>
        <?php } ?>
    </tbody>
    </table>
    <nav aria-label="Page navigation">
      <ul class="pagination">
      <?php if($currentPage != $firstPage) { ?>
        <li class="page-item">
          <a class="page-link" href="?page=<?php echo $firstPage ?>" tabindex="-1" aria-label="Previous">
            <span aria-hidden="true">First</span>           
          </a>
        </li>
        <?php } ?>
        <?php if($currentPage >= 2) { ?>
            <li class="page-item"><a class="page-link" href="?page=<?php echo $previousPage ?>"><?php echo $previousPage ?></a></li>
        <?php } ?>
        <li class="page-item active"><a class="page-link" href="?page=<?php echo $currentPage ?>"><?php echo $currentPage ?></a></li>
        <?php if($currentPage != $lastPage) { ?>
            <li class="page-item"><a class="page-link" href="?page=<?php echo $nextPage ?>"><?php echo $nextPage ?></a></li>
            <li class="page-item">
              <a class="page-link" href="?page=<?php echo $lastPage ?>" aria-label="Next">
                <span aria-hidden="true">Last</span>
              </a>
            </li>
        <?php } ?>
      </ul>
    </nav>
   
    <div style="margin:50px 0px 0px 0px;">
        <a class="btn btn-default read-more" style="background:#3399ff;color:white" href="http://www.phpzag.com/simple-code-for-pagination-in-php/">Back to Tutorial</a>       
    </div>
</div>
<?php include('footer.php');?>

simple contact form coding in php

 simple contact form coding in php
 contact-view.php



<html>
<head>
<title>Contact Us Form</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
    <div class="form-container">
        <form name="frmContact" id="" frmContact"" method="post"
            action="" enctype="multipart/form-data"
            onsubmit="return validateContactForm()">

            <div class="input-row">
                <label style="padding-top: 20px;">Name</label> <span
                    id="userName-info" class="info"></span><br /> <input
                    type="text" class="input-field" name="userName"
                    id="userName" />
            </div>
            <div class="input-row">
                <label>Email</label> <span id="userEmail-info"
                    class="info"></span><br /> <input type="text"
                    class="input-field" name="userEmail" id="userEmail" />
            </div>
            <div class="input-row">
                <label>Subject</label> <span id="subject-info"
                    class="info"></span><br /> <input type="text"
                    class="input-field" name="subject" id="subject" />
            </div>
            <div class="input-row">
                <label>Message</label> <span id="userMessage-info"
                    class="info"></span><br />
                <textarea name="content" id="content"
                    class="input-field" cols="60" rows="6"></textarea>
            </div>
            <div>
                <input type="submit" name="send" class="btn-submit"
                    value="Send" />

                <div id="statusMessage">
                        <?php
                        if (! empty($message)) {
                            ?>
                            <p class='<?php echo $type; ?>Message'><?php echo $message; ?></p>
                        <?php
                        }
                        ?>
                    </div>
            </div>
        </form>
    </div>

    <script src="https://code.jquery.com/jquery-2.1.1.min.js"
        type="text/javascript"></script>
    <script type="text/javascript">
        function validateContactForm() {
            var valid = true;

            $(".info").html("");
            $(".input-field").css('border', '#e0dfdf 1px solid');
            var userName = $("#userName").val();
            var userEmail = $("#userEmail").val();
            var subject = $("#subject").val();
            var content = $("#content").val();
           
            if (userName == "") {
                $("#userName-info").html("Required.");
                $("#userName").css('border', '#e66262 1px solid');
                valid = false;
            }
            if (userEmail == "") {
                $("#userEmail-info").html("Required.");
                $("#userEmail").css('border', '#e66262 1px solid');
                valid = false;
            }
            if (!userEmail.match(/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/))
            {
                $("#userEmail-info").html("Invalid Email Address.");
                $("#userEmail").css('border', '#e66262 1px solid');
                valid = false;
            }

            if (subject == "") {
                $("#subject-info").html("Required.");
                $("#subject").css('border', '#e66262 1px solid');
                valid = false;
            }
            if (content == "") {
                $("#userMessage-info").html("Required.");
                $("#content").css('border', '#e66262 1px solid');
                valid = false;
            }
            return valid;
        }
</script>
</body>
</html>


index.php


<?php
if(!empty($_POST["send"])) {
    $name = $_POST["userName"];
    $email = $_POST["userEmail"];
    $subject = $_POST["subject"];
    $content = $_POST["content"];

    $conn = mysqli_connect("localhost", "root", "test", "blog") or die("Connection Error: " . mysqli_error($conn));
    mysqli_query($conn, "INSERT INTO tblcontact (user_name, user_email,subject,content) VALUES ('" . $name. "', '" . $email. "','" . $subject. "','" . $content. "')");
    $insert_id = mysqli_insert_id($conn);
    //if(!empty($insert_id)) {
       $message = "Your contact information is saved successfully.";
       $type = "success";
    //}
}
require_once "contact-view.php";
?>



STYLE.CSS




body {
    font-family: Arial;
    width: 600px;
}

.form-container {
    background: #f1ecdf;
    border: #e2ddd2 1px solid;
    padding: 20px;
    border-radius: 2px;
}

.input-row {
    margin-bottom: 20px;
}

.input-row label {
    color: #75726c;
}

.input-field {
    width: 100%;
    border-radius: 2px;
    padding: 10px;
    border: #e0dfdf 1px solid;
    box-sizing: border-box;
    margin-top: 2px;
}

.span-field {
    font: Arial;
    font-size: small;
    text-decoration: none;
}

.btn-submit {
    padding: 10px 60px;
    background: #9e9a91;
    border: #8c8880 1px solid;
    color: #ffffff;
    font-size: 0.9em;
    border-radius: 2px;
    cursor: pointer;
}

.errorMessage {
    background-color: #e66262;
    border: #AA4502 1px solid;
    padding: 5px 10px;
    color: #FFFFFF;
    border-radius: 3px;
}

.successMessage {
    background-color: #9fd2a1;
    border: #91bf93 1px solid;
    padding: 5px 10px;
    color: #3d503d;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.9em;
}

.info {
    font-size: .8em;
    color: #e66262;
    letter-spacing: 2px;
    padding-left: 5px;
}


send_contact_mail.php


<?php
if(!empty($_POST["send"])) {
    $name = $_POST["userName"];
    $email = $_POST["userEmail"];
    $subject = $_POST["subject"];
    $content = $_POST["content"];

    $toEmail = "admin@phppot_samples.com";
    $mailHeaders = "From: " . $name . "<". $email .">\r\n";
    if(mail($toEmail, $subject, $content, $mailHeaders)) {
        $message = "Your contact information is received successfully.";
        $type = "success";
    }
}
require_once "contact-view.php";
?>

Php codeing for category and sub-category additing

 Php codeing for category_sub-category


<?php
include('include/connect.php');


/*Adding Category Program*/
if(isset($_POST['addcat']))
    {
    $category=$_POST['catname'];
  
    if(empty($category))
        {
        echo "<script>window.alert('Field is empty');</script>";
        }
    else
    {
    $sql="select max(id) from maincategory";
    $result=mysql_query($sql);
    $max=mysql_result($result,0,0);
    $max=$max+1;
  
  
$sql="INSERT INTO maincategory values('$max','$category')";
$result=mysql_query($sql);
    echo "<script>window.alert('$category added successfully'); window.location='addproduct.php';</script>";
    }
  

    }/*ADDING CATEGORY PROGRAM ENDS HERE*/
  
/*ADDING SUB-CATEGORY PROGRAM STARTS HERE*/
if(isset($_POST['subcategory']))
{
    $cat=$_POST['category'];
    $subcat=$_POST['subcatname'];
  
    if(empty($subcat))
        {
        echo "<script>window.alert('Field is empty')</script>";
        }
    else
        {
        $sql="select max(id) from subcategory";
        $result=mysql_query($sql);
        $max=mysql_result($result,0,0);
        $max=$max+1;
  
    $sql="insert into subcategory values('$max','$subcat','$cat')";
    $result=mysql_query($sql);
    echo "<script>window.alert('$subcat added successfully');window.location='addproduct.php';</script>";
        }
}


/*ADDING SUB-CATEGORY PROGRAM ENDS HERE*/


/*ADDING PRODUCT PROGRAM STARTS HERE*/
if(isset($_POST['submit']))
    {
    $pname=$_POST['pname'];
    $cat=$_POST['pcategory'];
    $subcat=$_POST['subcat'];
    $desc=$_POST['description'];
            if(empty($pname))
                {
                echo "<script>window.alert('Product Name is empty');</script>";
                }
            if($cat=="select_category")
                {
                echo "<script>window.alert('Category is not selected');</script>";
                }
            if($sub="select_subcategory")
                {
                echo "<script>window.alert('Sub-Category is not selected');</script>";
                }
          
            else
            {
      

$sql="select max(id) from product";
$result=mysql_query($sql);
$max=mysql_result($result,0,0);
$max=$max+1;

$sql="insert into product values('$max','$pname','$subcat','$desc')";
mysql_query($sql);
            }
  
    }
/*ADDING PRODUCT PROGRAM ENDS HERE*/
?>
<style>
label
{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
color:#333333;
}
span
{
font-family:Verdana, Arial, Helvetica, sans-serif;
color:maroon;
font-size:10px;
cursor:pointer;
}
span a
{
font-family:Verdana, Arial, Helvetica, sans-serif;
color:#CCCCCC;
font-size:9px;
text-decoration:none;
}
span a:hover
{
color:#666666;
}
#frame
{
height:100%;
width:100%;
background-color:#000000;
position:absolute;
top:0px;
left:0px;
opacity:0.5;
filter:alpha(opacity=50);
-moz-opacity:0.5;
z-index:1001;

}
#addcat
{
background-color:white;
position:absolute;
top:70px;
left:70px;
display:none;
z-index:1002;
}
#addsubcat
{
top:70px;
left:70px;
background-color:white;
position:absolute;
display:none;
z-index:1003;
}
</style>
<div id="frame" style="display:none;">
</div>
<form name="addproducnt" method="post" enctype="multipart/form-data">
<table border="1" cellspacing="0">
<tr>
    <td><label for="name">Name:</label></td>
    <td><input type="text" name="pname" id="name"/></td>
</tr>

<tr>
    <td><label for="description">Description</label></td>
    <td><input type="text" name="description" id="description"/></td>
</tr>

<tr>
    <td><label for="category">Select Category</label>  </td>
    <td>
    <select name="pcategory">
     
        <?php

        $sql="select * from maincategory";
        $result=mysql_query($sql);
        while($rec=mysql_fetch_array($result))
            {
          
            $catid=$rec['id'];
            $cat=$rec['name'];
          
              
            echo "<option value='$catid' onChange='subcat()'>$cat</option>";

            }
        ?>
      
    </select>
    <span><a href="#" onClick="javascript:document.getElementById('addcat').style.display='block'; document.getElementById('frame').style.display='block';">add category</a></span>
    </td>
</tr>

<tr>
    <td><label for="subcat">Select Sub Category</label></td>
    <td>
    <select name="subcat">
  
        <?php
      
      
        $sql="select * from subcategory where cat_id='$catid'";
        $result=mysql_query($sql);
            while($rec=mysql_fetch_array($result))
                {
              
                $id=$rec['id'];
                $name=$rec['name'];
                $cat_id=$rec['cat_id'];
              
                if($id==$catid)
                    {
                    $sel="selected";
                    }
                else
                    {
                    $sel="";
                    }
                echo "<option value=$id>$name</option>";
                  

                }
        ?>
    </select>
    <span><a href="#" onClick="javascript:document.getElementById('addsubcat').style.display='block';document.getElementById('frame').style.display='block';">add sub-category</a></span>
  
    </td>
</tr>

<tr>
  
</tr>

<tr>
    <td colspan="2" align="center"><input type="submit" name="submit" value="Add Product"/></td>
</tr>
</table>
<br><br>
<!--ADDING SUB-CATEGORY END-->
<div id="addcat">

<table border="1" cellspacing="0">
<tr>
    <th colspan="2" align="center">Add Category</th></tr>
    <td><label for="catname">Category Name:</label></td>
    <td><input type="text" name="catname" id="catname"/></td>
</tr>

<tr>
    <td colspan="2" align="center">
    <input type="submit" name="addcat" value="Add Category"/>
            <span onClick="javascript:document.getElementById('addcat').style.display='none';document.getElementById('frame').style.display='none';">Cancel</span>

    </td>
</tr>
</table>


</div>
<!--ADDING SUB-CATEGORY END-->


<!--ADDING SUB-CATEGORY START-->
<div id="addsubcat">
        <table border="1" cellspacing="0">
            <tr><th colspan="2">Sub Category</th></tr>
            <tr>
                <td>
                <label for="cat">Salect Category</label>
                </td>
                <td>
                <select name="category">
                    <?php
                    $sql="select * from maincategory";
                    $result=mysql_query($sql);
                        while($rec=mysql_fetch_array($result))
                            {
                            $id=$rec['id'];
                            $cat=$rec['name'];
                          
                            echo "<option value='$id'>$cat</option>";
                            }
                    ?>
                </select>
                </td>
            </tr>
          
          
            <tr>
                <td><label for="subcat">Add Sub Category</label></td>
                <td><input type="text" name="subcatname" id="subcat"></td>
            </tr>
          
            <tr>
            <td colspan="2" align="center"> <input type="submit" name="subcategory" value="Add Sub Category" /><span onClick="javascript:document.getElementById('frame').style.display='none';document.getElementById('addsubcat').style.display='none';">Cancel</span></td>
            </tr>
        </table>
    </div>
<!--ADDING SUB-CATEGORY END-->
</form>






 database  script




-- phpMyAdmin SQL Dump

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `project`
--

-- --------------------------------------------------------

--
-- Table structure for table `maincategory`
--

CREATE TABLE IF NOT EXISTS `maincategory` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `maincategory`
--

INSERT INTO `maincategory` (`id`, `name`) VALUES
(1, 'category_1'),
(2, 'category_2'),
(3, 'category_3'),
(4, 'category_4');

-- --------------------------------------------------------

--
-- Table structure for table `product`
--

CREATE TABLE IF NOT EXISTS `product` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `sub_cat` int(11) NOT NULL,
  `description` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `product`
--


-- --------------------------------------------------------

--
-- Table structure for table `subcategory`
--

CREATE TABLE IF NOT EXISTS `subcategory` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `cat_id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `subcategory`
--

INSERT INTO `subcategory` (`id`, `name`, `cat_id`) VALUES
(1, 's_cat_1', 1),
(2, 's_cat_1-cat_2', 2),
(3, 'subCat', 4),
(4, '4thSubCat', 4);
 



Sunday, 19 May 2019

How to create quiz pages on a Blogger blog


1. What is the answer to this question?






2. What is the answer to this question?




3. What is the answer to this question?




4. What is the answer to this question?




5. What is the answer to this question?




6. What is the answer to this question?




7. What is the answer to this question?




8. What is the answer to this question?




9. What is the answer to this question?




10. What is the answer to this question?





Show me the answers!
Question 1: The correct answer is the Answer 1.
Question 2: The correct answer is Answer 2.
Question 3: The correct answer is Answer 3.
Question 4: The correct answer is Answer 4.
Question 5: The correct answer is Answer 1.
Question 6: The correct answer is Answer 2.
Question 7: The correct answer is Answer 3.
Question 8: The correct answer is Answer 4.
Question 9: The correct answer is Answer 1.
Question 10: The correct answer is Answer 2.
You answered them all right!