Monday, 14 December 2015
Adding a column's value in a Listbox using php
<?php
$A = mysql_connect("LocalHost","root","") or die("Error in MYSQL Connection!");
mysql_select_db("attendencedb",$A) or die("Error in DataBase!");
$NA = mysql_query("SELECT concat(FirstName, ' ' , LastName) as Name FROM tblstudent") or die("Error in Selecting ID...!");
?>
<select name="dynamic_data">
<?php
$i=0;
while($row = mysql_fetch_array($NA)) {
?>
<option value="<?=$row["Name"];?>"><?=$row["Name"];?></option>
<?php
$i++;
}
?>
</select>
<?php
mysql_close($A);
?>
Sunday, 6 December 2015
Payroll Management
Login Form:
<?php
if(isset($_POST['btnlogin']))
{
$A = mysql_connect("LocalHost","root","") or die("Error in MYSQL Connection");
mysql_select_db("payroldb",$A) or die("Error in Data Base");
$NM = $_POST['txtName'];
$RN = $_POST['txtRegno'];
$query = mysql_query("SELECT * FROM tblemp where FirstName='".$NM."' AND RegNo='".$RN."'", $A) or die("Error in Select Query");
$row = mysql_fetch_array($query);
if($row["FirstName"]==$NM && $row["RegNo"]==$RN)
{
echo "<script> window.location.assign('index.php'); </script>";
echo "<a href='index.php?A=$rec[1] &B=$rec[3]></a></td>";
}
else
{
echo "<script>";
echo 'alert("Your Name OR Reg No is wrong...!")';
echo"</script>";
}
mysql_close($A);
}
?>
<div class="login-header text-center">
<br><br>
<img src="assets/img/team-back1.jpg">
</div>
<div class="login-wrapper">
<form action="login.php" method="post">
<div class="form-group has-feedback lg left-feedback no-label">
<input type="text" name="txtName" placeholder="Enter FirstName" autofocus required>
<span class="fa fa-user form-control-feedback"></span>
</div>
<div class="form-group has-feedback lg left-feedback no-label">
<input type="password" name="txtRegno" placeholder="Enter Reg.No" required>
<span class="fa fa-unlock-alt form-control-feedback"></span>
</div>
<div class="form-group">
</div>
<div class="form-group">
<button type="submit" name="btnlogin" >LOGIN</button>
</div>
</form>
</div><!-- /.login-wrapper -->
Add Employee:
<?php
if(isset($_POST['btnReg']))
{
$NM = $_POST['txtName'];
$LN = $_POST['txtLName'];
$UI = $_FILES['UImg']['name'];
$FT = $_FILES['UImg']['type'];
$FN = $_POST['txtFName'];
$CC = $_POST['txtNIC'];
$PN = $_POST['telno'];
$AD = $_POST['txtadres'];
$DB = $_POST['DOB'];
$GN = $_POST['rdoGend'];
$JD = $_POST['JDate'];
$RL = $_POST['lstRlgn'];
$DG = $_POST['txtDesg'];
$DP = $_POST['lstDept'];
$ST = $_POST['txtStatus'];
$RN = $_POST['txtRegno'];
if($FT =="image/jpeg" || $FT == "image/gif" || $FT=="image/png")
{
$A = mysql_connect("LocalHost","root","") or die("Error in MYSQL Connection");
mysql_select_db("payroldb",$A) or die("Error in Data Base");
mysql_query("Insert into tblemp values ('','$NM','$LN','$UI','$FN','$CC','$PN','$AD','$DB','$GN','$JD','$RL','$DG','$DP','$ST','$RN')", $A) or die("Error in Insert Query");
mysql_close($A);
echo '<script language="javascript">';
echo 'alert("Registered Successfuly...!")';
echo '</script>';
}
else
{
echo "Error: Select jpg | gif | png image.";
}
}
?>
<p>Begin your Registration here</p>
<!-- Begin basic form elements -->
<div class="row">
<div class="col-sm-6">
<!-- Begin basic form elements -->
<div class="the-box">
<h4 class="small-title">Employee's Information</h4>
<form action="add-emp.php" method="POST" Enctype="multipart/form-data">
<div class="form-group">
<label>First Name</label>
<input type="text" name="txtName" class="form-control rounded" placeholder="Enter First Name" required>
</div>
<div class="form-group">
<label>Last Name</label>
<input type="text" name="txtLName" class="form-control rounded" placeholder="Enter Last Name" required>
</div>
<div class="form-group">
<label>Upload Image</label>
<div class="input-group">
<input type="file" name="UImg" required>
</div><!-- /.input-group -->
</div>
<div class="form-group">
<label>Father Name</label>
<input type="text" name="txtFName" class="form-control rounded" placeholder="Enter Father Name" required>
</div>
<div class="form-group">
<label>NIC No</label>
<input type="text" name="txtNIC" class="form-control rounded" placeholder="Enter NIC No" required>
</div>
<div class="form-group">
<label>Phone No</label>
<input type="text" name="telno" class="form-control rounded" placeholder="Enter Phone No" required>
</div>
<div class="form-group">
<label>Address</label>
<textarea name="txtadres" class="form-control rounded no-resize bold-border" required></textarea>
</div>
<div class="form-group">
<label>Date of Birth</label>
<input type="date" name="DOB" class="form-control rounded" data-date-format="mm-dd-yy" placeholder="mm-dd-yy" required>
</div>
<div class="form-group">
<label>Gender</label>
<div class="radio">
<label>
<input type="radio" name="rdoGend" id="optionsRadios1" value="Male" checked>
Male
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="rdoGend" id="optionsRadios2" value="Female">
Female
</label>
</div>
</div>
<div class="form-group">
<label>Joining Date</label>
<input type="date" name="JDate" class="form-control rounded" data-date-format="mm-dd-yy" placeholder="mm-dd-yy" required>
</div>
<div class="form-group">
<label>Religion</label>
<select name="lstRlgn" class="form-control rounded">
<option value="Islam">Islam</option>
<option value="Baha’i Faith">Baha’i Faith</option>
<option value="Buddhism">Buddhism</option>
<option value="Christianity">Christianity</option>
<option value="Confucianism">Confucianism</option>
<option value="Hinduism">Hinduism</option>
<option value="Jainism">Jainism</option>
<option value="Judaism">Judaism</option>
<option value="Shinto">Shinto</option>
<option value="Sikhism">Sikhism</option>
<option value="Taoism">Taoism</option>
<option value="Zoroastrianism">Zoroastrianism</option>
<option value="Other">Other</option>
</select>
</div>
<div class="form-group">
<label>Designation</label>
<input type="text" name="txtDesg" class="form-control rounded" placeholder="Enter Designation" required>
</div>
<div class="form-group">
<label>Department</label>
<select name="lstDept" class="form-control rounded">
<option value="Customer Services">Customer Services</option>
<option value="Financial">Financial</option>
<option value="Human Resources">Human Resources</option>
<option value="Information Technology">Information Technology</option>
<option value="Inventory">Inventory</option>
<option value="Insuarence">Insuarence</option>
<option value="Licences">Licences</option>
<option value="Marketing">Marketing</option>
<option value="Operational">Operational</option>
<option value="Organizational">Organizational</option>
<option value="Purchasing">Purchasing</option>
<option value="Quality Asuarence">Quality Asuarence</option> <option value="Sales">Sales</option>
<option value="Staff">Staff</option>
<option value="Other Services">Other Services</option>
</select>
</div>
<div class="form-group">
<label>Working Status</label>
<input type="text" name="txtStatus" class="form-control rounded" placeholder="Enter Working Status" required>
</div>
<div class="form-group">
<label>Registration No</label>
<input type="text" name="txtRegno" class="form-control rounded" placeholder="Enter Registration No" required>
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" name="btnReg" value="Register">
</div>
</form>
</div><!-- /.the-box -->
<!-- End basic form elements -->
</div>
Search Employee:
<form method="get" action="Search-Emp.php" class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Enter First Name">
<input type="submit" name="submit" value="Search">
</div>
</form>
<br><br><br>
<!-- Begin basic form elements -->
<div class="row">
<div class="col-sm-6">
<table border=1>
<tr bgcolor="#CC99CC">
<th>Emp ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Image</th>
<th>Father Name</th>
<th>NIC</th>
<th>Phone Number</th>
<th>Address</th>
<th>Date Of Birth</th>
<th>Gender</th>
<th>Joining Date</th>
<th>Religion</th>
<th>Designation</th>
<th>Department</th>
<th>Working Status</th>
<th>Reg.No</th>
<th>Salary Slip</th>
</tr>
<?php
if (isset($_GET['name']))
{
$letter = $_GET['name'];
$A = mysql_connect("LocalHost","root","") or die("Error in MYSQL Connection!");
mysql_select_db("payroldb",$A) or die("Error in DataBase!");
$B = mysql_query("Select * from tblemp where FirstName like '%".$letter."%' || LastName like '%".$letter."%' || FatherName like '%".$letter."%' || Address like '%".$letter."%'",$A) or die("Error in Insert Query.");
$num_rows = mysql_num_rows($B);
if($num_rows == 1){
echo "<h2> $num_rows Employee </h2>";
}
else
echo "<h2> $num_rows Employees </h2>";
for($a=0; $a<$num_rows; $a++)
{
$rec = mysql_fetch_array($B);
echo "<tr>";
echo "<td>$rec[0]</td>";//EID
echo "<td>$rec[1]</td>";//First Name
echo "<td>$rec[2]</td>";//Last Name
echo "<td><img src='images/$rec[3]' width=50 height=50 border=5 Title='$rec[1]'></td>";//Image
echo "<td>$rec[4]</td>";//Father Name
echo "<td>$rec[5]</td>";//NIC
echo "<td>$rec[6]</td>";//Ph.No
echo "<td>$rec[7]</td>";//Address
echo "<td>$rec[8]</td>";//DOB
echo "<td>$rec[9]</td>";//Gender
echo "<td>$rec[10]</td>";//Joining Date
echo "<td>$rec[11]</td>";//Religion
echo "<td>$rec[12]</td>";//Designation
echo "<td>$rec[13]</td>";//Department
echo "<td>$rec[14]</td>";//Working Status
echo "<td>$rec[15]</td>";//Reg No
echo "<td><a href='SalarySlip.php?A=$rec[0]'>Salary Slip</a></td>";
echo "</tr>";
}
mysql_close($A);
}
?>
</table>
</div><!-- /.col-sm-6 -->
Update Employee:
<div class="row">
<div class="col-sm-6">
<!-- Begin basic form elements -->
<div class="the-box">
<h4 class="small-title">Employee's Information</h4>
<form action="Update-emp.php" method="POST" Enctype="multipart/form-data">
<div class="form-group">
<label>ID</label>
<input type="text" name="txtID" class="form-control rounded" Value="<?php echo $_GET['A'] ?>" readonly>
</div>
<div class="form-group">
<label>First Name</label>
<input type="text" name="txtName" class="form-control rounded" Value="<?php echo $_GET['B'] ?>" required>
</div>
<div class="form-group">
<label>Last Name</label>
<input type="text" name="txtLName" class="form-control rounded" Value="<?php echo $_GET['C'] ?>" required>
</div>
<div class="form-group">
<label>Image</label>
<input type="text" name="txtUImg" class="form-control rounded" Value="<?php echo $_GET['D'] ?>" required>
</div>
<div class="form-group">
<label>Father Name</label>
<input type="text" name="txtFName" class="form-control rounded" Value="<?php echo $_GET['E'] ?>" required>
</div>
<div class="form-group">
<label>NIC No</label>
<input type="text" name="txtNIC" class="form-control rounded" Value="<?php echo $_GET['F'] ?>" required>
</div>
<div class="form-group">
<label>Phone No</label>
<input type="text" name="telno" class="form-control rounded" Value="<?php echo $_GET['G'] ?>" required>
</div>
<div class="form-group">
<label>Address</label>
<input type="text" name="txtadres" class="form-control rounded" Value="<?php echo $_GET['H'] ?>" required>
</div>
<div class="form-group">
<label>Date of Birth</label>
<input type="text" name="DOB" class="form-control rounded" Value="<?php echo $_GET['I'] ?>" data-date-format="mm-dd-yy" required>
</div>
<div class="form-group">
<label>Gender</label>
<input type="text" name="rdoGend" class="form-control rounded" value="<?php echo $_GET['J']?>" required>
</div>
<div class="form-group">
<label>Joining Date</label>
<input type="text" name="JDate" class="form-control rounded" Value="<?php echo $_GET['K'] ?>" data-date-format="mm-dd-yy" required>
</div>
<div class="form-group">
<label>Religion</label>
<input type="text" name="lstRlgn" class="form-control rounded" Value="<?php echo $_GET['L'] ?>">
</div>
<div class="form-group">
<label>Designation</label>
<input type="text" name="txtDesg" class="form-control rounded" Value="<?php echo $_GET['M'] ?>" required>
</div>
<div class="form-group">
<label>Department</label>
<input type="text" name="lstDept" class="form-control rounded" Value="<?php echo $_GET['N'] ?>">
</div>
<div class="form-group">
<label>Working Status</label>
<input type="text" name="txtStatus" class="form-control rounded" Value="<?php echo $_GET['O'] ?>" required>
</div>
<div class="form-group">
<label>Registration No</label>
<input type="text" name="txtRegno" class="form-control rounded" Value="<?php echo $_GET['P'] ?>" required>
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" name="btnUpdate" value="Update">
<input class="btn btn-primary" type="button" onClick="Back()" value="Back">
</div>
</form>
<script>
function Back()
{
document.location.href='view-emp.php';
}
</script>
</div><!-- /.the-box -->
<!-- End basic form elements -->
</div><!-- /.col-sm-6 -->
<?php
if(isset($_POST['btnUpdate']))
{
$ID = $_POST['txtID'];
$NM = $_POST['txtName'];
$LN = $_POST['txtLName'];
$IM = $_POST['txtUImg'];
$FN = $_POST['txtFName'];
$CC = $_POST['txtNIC'];
$PN = $_POST['telno'];
$AD = $_POST['txtadres'];
$DB = $_POST['DOB'];
$GN = $_POST['rdoGend'];
$JD = $_POST['JDate'];
$RL = $_POST['lstRlgn'];
$DG = $_POST['txtDesg'];
$DP = $_POST['lstDept'];
$ST = $_POST['txtStatus'];
$RN = $_POST['txtRegno'];
$A = mysql_connect("LocalHost","root","") or die("Error in MYSQL Connection");
mysql_select_db("payroldb",$A) or die("Error in Data Base");
mysql_query("Update tblemp set FirstName='$NM', LastName='$LN',Image='$IM', FatherName='$FN', NIC='$CC', PhoneNo='$PN', Address='$AD', DOB='$DB', Gender='$GN', JoiningDate='$JD', Religion='$RL', Designation='$DG', Department= '$DP', WorkingStatus='$ST', RegNo='$RN' Where ID='$ID'", $A) or die("Error in Update Query");
mysql_close($A);
echo '<script language="javascript">';
echo 'alert("Updated Successfuly...!")';
echo '</script>';
}
?>
View Employee:
<?php
if(isset($_GET['A']))
{
$P = $_GET['A'];
$A = mysql_connect("localhost","root","") or die ("error in sql connection");
mysql_select_db("payroldb",$A) or die ("error in database");
mysql_query("delete from tblemp Where ID=$P",$A) or die ("error in query");
mysql_close($A);
}
?>
<?php
$A = mysql_connect("LocalHost","root","") or die("Error in MYSQL Connection!");
mysql_select_db("payroldb",$A) or die("Error in DataBase!");
$B = mysql_query("Select * from tblemp",$A) or die("Error in Select Query.");
$num_rows = mysql_num_rows($B);
if($num_rows == 1)
{
echo "<h2> $num_rows Employee </h2>";
}
else
{
echo "<h2> $num_rows Employees </h2>";
}
?>
<p style="color:#F00">Click on the First Name to edit the employee's Information...!</p>
&
<p style="color:#F00">Click on the Last Name to delete the employee's Information...!</p>
<table border="1">
<thead bgcolor="#FFFFFF">
<tr>
<th>Emp ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Image</th>
<th>Father Name</th>
<th>NIC</th>
<th>Phone Number</th>
<th>Address</th>
<th>Date Of Birth</th>
<th>Gender</th>
<th>Joining Date</th>
<th>Religion</th>
<th>Designation</th>
<th>Department</th>
<th>Working Status</th>
<th>Reg.No</th>
</tr>
</thead>
<?php
for($a=0; $a<$num_rows; $a++)
{
$rec=mysql_fetch_array($B);
echo "<tr>";
echo "<td>$rec[0]</td>";//EID
echo "<td><a href='Update-emp.php?A=$rec[0] &B=$rec[1] &C=$rec[2] &D=$rec[3] &E=$rec[4] &F=$rec[5] &G=$rec[6] &H=$rec[7] &I=$rec[8] &J=$rec[9] &K=$rec[10] &L=$rec[11] &M=$rec[12] &N=$rec[13] &O=$rec[14] &P=$rec[15]'>$rec[1]</a></td>";//First Name?>
<td><a onClick="return confirm('Are you sure you want to delete this record?')"
href='view-emp.php?A=<?php echo $rec[0] ?>'><?php echo " $rec[2]" ?></a></td><?php //Last Name
echo "<td><img src='images/$rec[3]' width=50 height=50 border=5 Title='$rec[1]'></td>";//Image
echo "<td>$rec[4]</td>";//Father Name
echo "<td>$rec[5]</td>";//NIC
echo "<td>$rec[6]</td>";//Ph.No
echo "<td>$rec[7]</td>";//Address
echo "<td>$rec[8]</td>";//DOB
echo "<td>$rec[9]</td>";//Gender
echo "<td>$rec[10]</td>";//Joining Date
echo "<td>$rec[11]</td>";//Religion
echo "<td>$rec[12]</td>";//Designation
echo "<td>$rec[13]</td>";//Department
echo "<td>$rec[14]</td>";//Working Status
echo "<td>$rec[15]</td>";//Reg No
echo "</tr>";
}
mysql_close($A);
?>
</table>
Monday, 30 November 2015
Reading and printing a (.txt) file on web page in PHP & Save the data to Database
<?php
$myfile = fopen("time.txt", "r") or die("Unable to open file!");
while(!feof($myfile)) {
$x = fgets($myfile);
echo $x;
echo "<br>"; //save it to DB
$A = mysql_connect("LocalHost","root","") or die("Error in MYSQL Connection");
mysql_select_db("payroldb",$A) or die("Error in Data Base");
mysql_query("insert into tbltime values('','".$x."','".$x."')",$A) or die("Error in insert query!");
mysql_close($A);
}
fclose ($myfile);
?>
Confirm Message at Delete button
HTML Code:
<td><a onClick="return confirm('Are you sure you want to delete this record?')"
href='view-emp.php?A=<?php echo $rec[0] ?>'><?php echo " $rec[2]" ?></a></td>
PHP Code:
<?php
if(isset($_GET['A']))
{
$P = $_GET['A'];
$A = mysql_connect("localhost","root","") or die ("error in sql connection");
mysql_select_db("payroldb",$A) or die ("error in database");
mysql_query("delete from tblemp Where ID=$P",$A) or die ("error in query");
mysql_close($A);
}
?>
Thursday, 26 November 2015
File upload and move to folder
Index Page/Main Page/Form:
<html>
<head>
<title>Upload File</title>
</head>
<body>
<table align="center">
<tr>
<td><fieldset>
<legend>Upload File</legend>
<form action="upload.php" method="POST" Enctype="multipart/form-data">
<input type="file" name="file"><br><br>
<input type="Submit" name="btnSave" value="Upload">
</form></fieldset>
</td></tr>
<tr>
<td></td>
</tr>
</table>
</body>
</html>
Description Page with PHP code:
<html>
<head>
<title>Description</title>
</head>
<body>
<table align="center">
<tr><td>
<?php
if (isset($_POST['btnSave'])){
if(!file_exists("upload"))
{
mkdir("upload");
}
if($_FILES["file"]["error"] > 0)
{
$er="ERROR Return Code:".$_FILES["file"]["error"]."<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
$file = $_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"],"upload/".$_FILES["file"]["name"]);
echo "Stored in" , " upload/" , $_FILES["file"]["name"];
}
}
?>
<br>
<a href="indexx.php">Back</a>
<?php
//echo $er;
?>
</td></tr>
</table>
</body>
</html>
Captcha
<html>
<head>
<title>Captcha Validation</title>
<script type="text/javascript">
function DrawCaptcha()
{
var a = Math.ceil(Math.random() * 10)+ '';
var b = Math.ceil(Math.random() * 10)+ '';
var c = Math.ceil(Math.random() * 10)+ '';
var d = Math.ceil(Math.random() * 10)+ '';
var e = Math.ceil(Math.random() * 10)+ '';
var f = Math.ceil(Math.random() * 10)+ '';
var g = Math.ceil(Math.random() * 10)+ '';
var code = a + ' ' + b + ' ' + ' ' + c + ' ' + d + ' ' + e + ' '+ f + ' ' + g;
document.getElementById("txtCaptcha").value = code
}
function ValidCaptcha(){
var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
var str2 = removeSpaces(document.getElementById('txtInput').value);
if (str1 == str2) return true;
return false;
}
function removeSpaces(string)
{
return string.split(' ').join('');
}
</script>
</head>
<body onload="DrawCaptcha();">
<div class="align">
Welcome To Captcha<br />
<input id="txtCaptcha" type="text" readonly="" class="input_img">
<input type="button" id="btnrefresh" value="Refresh" onclick="DrawCaptcha();" /><br>
<input type="text" id="txtInput"/>
<input id="Button1" type="button" value="Check" onclick="alert(ValidCaptcha());"/>
</div>
<p style="color:#F36">- See more at: http://codingresolved.com/discussion/540/how-to-make-captcha-in-javascript/p1#sthash.3nlKLUxl.dpuf</p>
</body>
</html>
<head>
<title>Captcha Validation</title>
<script type="text/javascript">
function DrawCaptcha()
{
var a = Math.ceil(Math.random() * 10)+ '';
var b = Math.ceil(Math.random() * 10)+ '';
var c = Math.ceil(Math.random() * 10)+ '';
var d = Math.ceil(Math.random() * 10)+ '';
var e = Math.ceil(Math.random() * 10)+ '';
var f = Math.ceil(Math.random() * 10)+ '';
var g = Math.ceil(Math.random() * 10)+ '';
var code = a + ' ' + b + ' ' + ' ' + c + ' ' + d + ' ' + e + ' '+ f + ' ' + g;
document.getElementById("txtCaptcha").value = code
}
function ValidCaptcha(){
var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
var str2 = removeSpaces(document.getElementById('txtInput').value);
if (str1 == str2) return true;
return false;
}
function removeSpaces(string)
{
return string.split(' ').join('');
}
</script>
</head>
<body onload="DrawCaptcha();">
<div class="align">
Welcome To Captcha<br />
<input id="txtCaptcha" type="text" readonly="" class="input_img">
<input type="button" id="btnrefresh" value="Refresh" onclick="DrawCaptcha();" /><br>
<input type="text" id="txtInput"/>
<input id="Button1" type="button" value="Check" onclick="alert(ValidCaptcha());"/>
</div>
<p style="color:#F36">- See more at: http://codingresolved.com/discussion/540/how-to-make-captcha-in-javascript/p1#sthash.3nlKLUxl.dpuf</p>
</body>
</html>
Tuesday, 17 November 2015
Search Box code in PHP
HTML Tags:
<form method="get" action="Search-Emp.php" class="navbar-form navbar-left" role="search">
<input type="text" name="name" class="form-control" placeholder="Search">
<input type="submit" name="submit" value="Search">
</form>
<br><br><br>
<table border=1>
<tr bgcolor="#CC99CC">
<th>Emp ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Image</th>
<th>Father Name</th>
<th>NIC</th>
<th>Phone Number</th>
<th>Address</th>
<th>Date Of Birth</th>
<th>Gender</th>
<th>Joining Date</th>
<th>Religion</th>
<th>Designation</th>
<th>Department</th>
<th>Working Status</th>
<th>Reg.No</th>
</tr>
</table>
PHP Code:
<?php
if (isset($_GET['name']))
{
$letter = $_GET['name'];
$A = mysql_connect("LocalHost","root","") or die("Error in MYSQL Connection!");
mysql_select_db("payroldb",$A) or die("Error in DataBase!");
$B = mysql_query("Select * from tblemp where FirstName like '%".$letter."%'",$A) or die("Error in Insert Query.");
$num_rows = mysql_num_rows($B);
if($num_rows == 1){
echo "<h2> $num_rows Employee </h2>";
}
else
echo "<h2> $num_rows Employees </h2>";
for($a=0; $a<$num_rows; $a++)
{
$rec = mysql_fetch_array($B);
echo "<tr>";
echo "<td>$rec[0]</td>";//EID
echo "<td>$rec[1]</a></td>";//First Name
echo "<td>$rec[2]</td>";//Last Name
echo "<td><img src='images/$rec[3]' width=50 height=50 border=5 Title='$rec[1]'></td>";//Image
echo "<td>$rec[4]</td>";//Father Name
echo "<td>$rec[5]</td>";//NIC
echo "<td>$rec[6]</td>";//Ph.No
echo "<td>$rec[7]</td>";//Address
echo "<td>$rec[8]</td>";//DOB
echo "<td>$rec[9]</td>";//Gender
echo "<td>$rec[10]</td>";//Joining Date
echo "<td>$rec[11]</td>";//Religion
echo "<td>$rec[12]</td>";//Designation
echo "<td>$rec[13]</td>";//Department
echo "<td>$rec[14]</td>";//Working Status
echo "<td>$rec[15]</td>";//Reg No
echo "</tr>";
}
mysql_close($A);
}
?>
Thursday, 12 November 2015
Easy code for radio button
Data Base:
CREATE TABLE
`data`.`tb` (`name` VARCHAR( 25 ) NOT NULL ,
`color` VARCHAR( 5 ) NOT NULL)
ENGINE = INNODB;
PHP & HTML:
<html>
<body>
<?php
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$color=$_POST['color'];
if($name!="" && $color!="")
{
$query=mysql_query("insert into tb values('$name','$color')");
if($query)
{
echo "Updated successfully!";
}
else
{
echo "there is a problem in Databse";
}
}
else
{
echo "Please fill all details";
}
}
else
{
?>
Which Color your like most?
<br />
<form method="post" action="index.php">
Name:<input type="text" name="name" /><br />
<input type="radio" name="color" value="Red" />Red
<input type="radio" name="color" value="Green" />Green
<input type="radio" name="color" value="Black" />Black
<input type="radio" name="color" value="White" />White
<input type="submit" name="submit" />
</form>
<?php
}
?>
</body>
</html>
<html>
<body>
<?php
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$color=$_POST['color'];
if($name!="" && $color!="")
{
$query=mysql_query("insert into tb values('$name','$color')");
if($query)
{
echo "Updated successfully!";
}
else
{
echo "there is a problem in Databse";
}
}
else
{
echo "Please fill all details";
}
}
else
{
?>
Which Color your like most?
<br />
<form method="post" action="index.php">
Name:<input type="text" name="name" /><br />
<input type="radio" name="color" value="Red" />Red
<input type="radio" name="color" value="Green" />Green
<input type="radio" name="color" value="Black" />Black
<input type="radio" name="color" value="White" />White
<input type="submit" name="submit" />
</form>
<?php
}
?>
</body>
</html>
Code for Radio Button
<?PHP
$selected_radio = $_POST['gender'];
print $selected_radio;
print $selected_radio;
?>
if (isset($_POST['Submit1'])) {
$selected_radio = $_POST['gender'];
print $selected_radio;
print $selected_radio;
}
The PHP code:
The PHP code:
<?PHP
$male_status = 'unchecked';
$female_status = 'unchecked';
$female_status = 'unchecked';
if (isset($_POST['Submit1'])) {
$selected_radio = $_POST['gender'];
if ($selected_radio = = 'male') {
$male_status = 'checked';
}
else if ($selected_radio = = 'female') {
else if ($selected_radio = = 'female') {
$female_status = 'checked';
}
}
?>
The HTML FORM code:
<FORM name ="form1" method ="post" action ="radioButton.php">
<Input type = 'Radio' Name ='gender' value= 'male'
<?PHP print $male_status; ?>
>Male
<?PHP print $male_status; ?>
>Male
<Input type = 'Radio' Name ='gender' value= 'female'
<?PHP print $female_status; ?>
>Female
<?PHP print $female_status; ?>
>Female
<P>
<Input type = "Submit" Name = "Submit1" VALUE = "Select a Radio Button">
<Input type = "Submit" Name = "Submit1" VALUE = "Select a Radio Button">
</FORM>
Wednesday, 11 November 2015
Image Uploading in a Form Table
Button's Code:
<?php
if(isset($_POST['btnSave']))
{
$UN = $_POST['txtName'];
$PH = $_POST['txtPhone'];
$EM = $_POST['txtEmail'];
$FN = $_FILES['UFile']['name'];
$FT = $_FILES['UFile']['type'];
$TN = $_FILES['UFile']['tmp_name'];
echo "Temp Name: $TN<br>";
if($FT =="image/jpeg" || $FT == "image/gif" || $FT=="image/png")
{
move_uploaded_file($TN,"Data/$FN");
$A = mysql_connect("LocalHost","root","") or die("Error in MYSQL Connection!");
mysql_select_db("BahriaDB",$A) or die("Error in DataBase!");
mysql_query("Insert into tblRegister values ('','$UN','$PH','$EM','$FN')",$A) or die("Error in Insert Query.");
mysql_close($A);
}
else
{ echo "Error: Select jpg | gif | png image."; }
}
?>
Form's Code:
<html>
<body>
<form action="Attach.php" method="POST" Enctype="multipart/form-data">
<table border=1 CellPadding=5 CellSpacing=5>
<tr>
<td>Name</td>
<td><input type=Text name=txtName required=required></td>
</tr>
<tr>
<td>Phone</td>
<td><input type=Text name=txtPhone required=required></td>
</tr>
<tr>
<td>Email</td>
<td><input type=Text name=txtEmail required=required></td>
</tr>
<tr>
<td>Select Image</td>
<td><input type=File name=UFile></td>
</tr>
<tr>
<td>.</td>
<td><input type=Submit name=btnSave value=Save></td>
</tr>
</table>
</form>
Table's View:
<table border=1 CellPadding=5 CellSpacing=5>
<tr BGColor=Aqua> <th>RID</th> <th>Name</th> <th>Phone</th> <th>E-Mail</th> <th>Image</th> </tr>
<?php
$A = mysql_connect("LocalHost","root","") or die("Error in MYSQL Connection!");
mysql_select_db("BahriaDB",$A) or die("Error in DataBase!");
$B = mysql_query("Select * from tblRegister",$A) or die("Error in Insert Query.");
$T = mysql_num_rows($B);
echo "Total Records: $T<br>";
for($a=0; $a<$T; $a++)
{
$R = mysql_fetch_array($B);
echo "<tr>";
echo "<td>$R[0]</td>";//RID
echo "<td><a href='Detail.php?A=$R[0]'>$R[1]</a></td>";//Name
echo "<td>$R[2]</td>";//PHone
echo "<td>$R[3]</td>";//Email
echo "<td><img src='Data/$R[4]' width=100 height=100 border=5 Title='$R[1]'></td>";
echo "</tr>";
}
mysql_close($A);
?>
</table>
</html>
Registration Code
Button's Code In PHP:
<?php
if(isset($_POST['btnReg']))
{
$NM = $_POST['txtName'];
$EM = $_POST['txtEmail'];
$PD = $_POST['txtPwd'];
$PH = $_POST['txtPhno'];
$AD = $_POST['txtAdd'];
$OC = $_POST['txtOcc'];
$A = mysql_connect("LocalHost","root","") or die("Error in MYSQL Connection");
mysql_select_db("asd",$A) or die("Error in Data Base");
mysql_query("Insert into tbluser values ('','$NM','$EM','$PD','$PH','$AD','$OC')", $A) or die("Error in Insert Query");
mysql_close($A);
echo '<script language="javascript">';
echo 'alert("Registered Successfuly...!")';
echo '</script>';
}
?>
Form's Code in HTML:
<div id="templatemo_content_right">
<h1 align="center">Registration Form</h1>
<form action="Reg.php" method="post">
<table border=1 CellPadding=5 CellSpacing=5 align="center">
<tr>
<td>Name</td>
<td><input type="text" name="txtName" Required="required" placeholder="Enter Name" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="email" name="txtEmail" Required="required" PlaceHolder="Enter Email" /></td>
</tr>
<tr>
<td>Passward</td>
<td><input type="password" name="txtPwd" Required="required" placeholder="Enter Passward" /></td>
</tr>
<tr>
<td>Phone.No</td>
<td><input type="text" name="txtPhno" Required="required" placeholder="Enter Phone.No" /></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="txtAdd" Required="required" placeholder="Enter Address" /></td>
</tr>
<tr>
<td>Occupation</td>
<td><input type="text" name="txtOcc" Required="required" placeholder="Enter Occupation" /></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" name="btnReg" value="Register Me"></td>
</tr>
<!--<button id="btnreg" onclick="reg()">Register Me...!</button>-->
</table>
</form>
</div>
Wednesday, 4 November 2015
GO to next page after LOGIN
<?php
if(isset($_POST['name_of_login_button']))
{
$A = mysql_connect("LocalHost","root","") or die("Error in MYSQL Connection");
mysql_select_db("name_of_database",$A) or die("Error in Data Base");
$NM = $_POST['name_of_first_textfield']; // that may be 'txtName'
$PD = $_POST['name_of_second_textfield']; // that may be 'txtPwd'
$query = mysql_query("SELECT * FROM name_of_table where column_name_for_Name='".$NM."' AND column_name_for_Passward='".$PD."'", $A) or die("Error in Select Query");
$row = mysql_fetch_array($query);
if($row["column_name_for_Name"]==$NM && $row["column_name_for_Passward"]==$PD)
{
echo "<script> window.location.assign('name_of_page.php'); </script>";
}
else
{
echo"Your password is wrong";
}
mysql_close($A);
}
?>
if(isset($_POST['name_of_login_button']))
{
$A = mysql_connect("LocalHost","root","") or die("Error in MYSQL Connection");
mysql_select_db("name_of_database",$A) or die("Error in Data Base");
$NM = $_POST['name_of_first_textfield']; // that may be 'txtName'
$PD = $_POST['name_of_second_textfield']; // that may be 'txtPwd'
$query = mysql_query("SELECT * FROM name_of_table where column_name_for_Name='".$NM."' AND column_name_for_Passward='".$PD."'", $A) or die("Error in Select Query");
$row = mysql_fetch_array($query);
if($row["column_name_for_Name"]==$NM && $row["column_name_for_Passward"]==$PD)
{
echo "<script> window.location.assign('name_of_page.php'); </script>";
}
else
{
echo"Your password is wrong";
}
mysql_close($A);
}
?>
Insertion & Selection of data in PHP
Insertion:
<?php
if(isset($_POST['btnSave']))
{
$MN = $_POST['txtA'];
$RD = $_POST['txtB'];
$RT = $_POST['Rating'];
$A = mysql_connect("LocalHost","root","") or die("Error in MySQL Connection"); //Step-1: Open Connection
mysql_select_db("MovieDB",$A) or die ("Error in Data Base"); //Step-2: Select Data Base.
mysql_query("Insert into tblMovies values ('','$MN','$RD','$RT')",$A) or die ("Error in Insert Query"); //Step-3: Run Query
mysql_close($A); //Step-4: Close DataBase.
echo "Data Saved.";
}
?>
Selection:
<?php
$A = mysql_connect("LocalHost","root","") or die("Error in MySQL Connection"); //Step-1: Open Connection
mysql_select_db("MovieDB",$A) or die ("Error in Data Base"); //Step-2: Select Data Base.
$B = mysql_query("Select * from tblMovies",$A) or die ("Error in Insert Query"); //Step-3: Run Query
$T = mysql_num_rows($B);
echo "Total Rows: $T <br>";
for($a=0; $a<$T; $a++)
{
$R = mysql_fetch_array($B);
echo "<tr>";
echo "<td>$R[0]</td>"; //MID
echo "<td>$R[1]</td>"; //MovieName
echo "<td>$R[2]</td>"; //ReleaseDate
echo "<td>$R[3]</td>"; //Rating
echo "<td align=center><font color=Blue><img src='Movies/$R[0].jpg' width=70 height=70 title='$R[1]' border=5></font></td>"; //Images
echo "</tr>";
}
mysql_close($A); //Step-4: Close DataBase.
?>
Form:
<h2><strong>Fill Movie Information</strong></h2>
<Form action="Index.php" Method="POST">
<table border=1 cellspacing=5 cellpadding=5>
<tr>
<td><input type=Text name=txtA PlaceHolder="Enter Movie Name" Required=Required></td>
</tr>
<tr>
<td><input type=Text name=txtB PlaceHolder="Enter Release Date" Required=Required></td>
</tr>
<tr>
<td><Select name=Rating Style=Width:145>
<option>Select Rating</option>
<option>1-Star</option>
<option>2-Star</option>
<option>3-Star</option>
<option>4-Star</option>
</Select></td>
</tr>
<tr>
<td align=right><input type=Submit name=btnSave Value=Save></td>
</tr>
</table>
</Form>
Subscribe to:
Posts (Atom)