Return to Snippet

Revision: 66203
at March 27, 2014 17:15 by Ankur


Updated Code
<?php include("includes/connection.php");?>
<?php
session_start();
if(!(isset($_SESSION['adminname'])))
{
	header("Location:front/login.php");
	exit();
}
?>
<?php
$offset=(5*60*60)+(30*60);
$format="Y-m-d H:i:s";
$time=gmdate($format,(time()+$offset));
?>
<?php $i=rand();?>
<?php
if(isset($_POST['add']))
{
	$code=$i;
	$bname=$con->real_escape_string($_POST['bname']);          //OOP Used only here!
	$incharge=$con->real_escape_string($_POST['incharge']);
	$contact=$con->real_escape_string($_POST['contact']);
	$email=$con->real_escape_string($_POST['email']);
	$address=$con->real_escape_string($_POST['address']);
	$lastlogged=0;
	
	if(empty($incharge) || empty($bname) || empty($email) || empty($address))
	{
		echo "<script type='text/javascript'>alert('Please fill the required fields!');</script>";
	}
	else
	{
		$q="insert into branch (code,bname,incharge,lastlogged,createdon,contactno,email,address) 
			values('$i','$bname','$incharge','$lastlogged','$time','$contact','$email','$address')";
		$res=$con->query($q);
		if($res)
		{
			echo "<script type='text/javascript'>alert('Branch Successfully Added!');</script>";
		}
		else
		{
			echo "<script type='text/javascript'>alert('Something went wrong,Try Again!');</script>";
		}
	}
}
else
{
	$bname="";
	$incharge="";
	$lastlogged="";
	$contact="";
	$email="";
	$address="";
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>
<body>
<center>
<p class="bheading">Add New Branch</p>
<form action="addb.php" method="post">
<table cellpadding="5" cellspacing="5">
<tr>
<td>Code:</td><td><?php echo $i;?></td>
</tr>
<tr>
<td>Branch Name:</td><td><input type="text" name="bname" size="38"></td>
</tr>
<tr>
<td>Incharge:</td><td><input type="text" name="incharge" size="38"></td>
</tr>
<tr>
<td>Contact No:</td><td><input type="number" name="contact" style="width:100%"></td>
</tr>
<tr>
<td>Email:</td><td><input type="email" name="email" size="38"></td>
</tr>
<tr>
<td>Address:</td><td><input type="text" name="address" size="38"></td>
</tr>
</table></br></br>
<input type="Submit" name="add" value="Add Branch">					
</form>
</center>
</body>
</html>

Revision: 66202
at March 27, 2014 17:11 by Ankur


Initial Code
<?php include("includes/connection.php");?>
<?php
session_start();
if(!(isset($_SESSION['adminname'])))
{
	header("Location:front/login.php");
	exit();
}
?>
<?php
$offset=(5*60*60)+(30*60);
$format="Y-m-d H:i:s";
$time=gmdate($format,(time()+$offset));
?>
<?php $i=rand();?>
<?php
if(isset($_POST['add']))
{
	$code=$i;
	$bname=$con->real_escape_string($_POST['bname']);
	$incharge=$con->real_escape_string($_POST['incharge']);
	$contact=$con->real_escape_string($_POST['contact']);
	$email=$con->real_escape_string($_POST['email']);
	$address=$con->real_escape_string($_POST['address']);
	$lastlogged=0;
	
	if(empty($incharge) || empty($bname) || empty($email) || empty($address))
	{
		echo "<script type='text/javascript'>alert('Please fill the required fields!');</script>";
	}
	else
	{
		$q="insert into branch (code,bname,incharge,lastlogged,createdon,contactno,email,address) 
			values('$i','$bname','$incharge','$lastlogged','$time','$contact','$email','$address')";
		$res=$con->query($q);
		if($res)
		{
			echo "<script type='text/javascript'>alert('Branch Successfully Added!');</script>";
		}
		else
		{
			echo "<script type='text/javascript'>alert('Something went wrong,Try Again!');</script>";
		}
	}
}
else
{
	$bname="";
	$incharge="";
	$lastlogged="";
	$contact="";
	$email="";
	$address="";
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>
<body>
<center>
<p class="bheading">Add New Branch</p>
<form action="addb.php" method="post">
<table cellpadding="5" cellspacing="5">
<tr>
<td>Code:</td><td><?php echo $i;?></td>
</tr>
<tr>
<td>Branch Name:</td><td><input type="text" name="bname" size="38"></td>
</tr>
<tr>
<td>Incharge:</td><td><input type="text" name="incharge" size="38"></td>
</tr>
<tr>
<td>Contact No:</td><td><input type="number" name="contact" style="width:100%"></td>
</tr>
<tr>
<td>Email:</td><td><input type="email" name="email" size="38"></td>
</tr>
<tr>
<td>Address:</td><td><input type="text" name="address" size="38"></td>
</tr>
</table></br></br>
<input type="Submit" name="add" value="Add Branch">					
</form>
</center>
</body>
</html>

Initial URL
myoop

Initial Description
Making it OOP way.

Initial Title
PHP Form handling

Initial Tags


Initial Language
PHP