Answer Posted / sekar
<?php
include_once("config/dbcon.php");
admin_html();
if($_POST['submit']=='INSERT'){
admin_insert();
}
elseif($_GET['type']=='list'){
$id=0;
$cl_name=0;$cl_place=0;$cl_site=0;$cl_logo=0;$cl_category=0;
admin_list($id,$cl_name,$cl_place,$cl_site,$cl_logo,$cl_category);
}
elseif($_GET['type']=='del'){
admin_delete();
}
elseif($_GET['type']=='update'){
admin_update();
}
function admin_html(){
$display = "<form method='post' action=''
enctype='multipart/form-data'>
<table align='center' border='1' cellpadding='10'
cellspacing='5' width='700'>
<tr>
<td width='100%' align='center' colspan='3'><h3>College
information</h3></td>
</tr>
<tr>
<td width='40%' align='center'>College Name</td>
<td width='10%' align='center'>:</td>
<td width='50%' align='center'><input type='text'
name='cl_name'></td>
</tr>
<tr>
<td width='40%' align='center'>College Place</td>
<td width='10%' align='center'>:</td>
<td width='50%' align='center'><input type='text'
name='cl_place'></td>
</tr>
<tr>
<td width='40%' align='center'>College site</td>
<td width='10%' align='center'>:</td>
<td width='50%' align='center'><input type='text'
name='cl_site'></td>
</tr>
<tr>
<td width='40%' align='center'>College Category</td>
<td width='10%' align='center'>:</td>
<td width='50%' align='center'>
<select name='cl_cat'>
<option value='-1'>Please Select anyone</option>
<option value='mediacl'>Medical</option>
<option value='art'>Art</option>
<option value='engg'>Engg</option>
</select>
</td>
</tr>
<tr>
<td width='40%' align='center'>College Logo</td>
<td width='10%' align='center'>:</td>
<td width='50%' align='center'><input type='file'
name='cl_logo'></td>
</tr>
<tr>
<td width='50%' align='center' colspan='2'><input
type='submit' value='INSERT' name='submit'></td>
<td width='50%' align='center'><a
href='admin.php?type=list'>EDIT</a></td>
</tr>";
echo $display;
}
function admin_insert(){
$cn = $_POST["cl_name"];
$cp = $_POST["cl_place"];
$cs = $_POST["cl_site"];
$cc = $_POST["cl_cat"];
$cl = admin_upload();
$select = "select cl_name, cl_place, cl_site from
collegeinformation";
$row = mysql_query($select);
$count = mysql_num_rows($row);
$insert = "insert into collegeinformation(cl_name,
cl_place, cl_site,
cl_logo,cl_category)values('$cn','$cp','$cs','$cc','$cl')";
$result = mysql_query($insert);
if($insert){
echo "1 record added";
}
else{
echo "No record added";
}
}
function admin_upload(){
$name = $_FILES['cl_logo']['name'];
$type = $_FILES['cl_logo']['type'];
$size = $_FILES['cl_logo']['size'];
$tmp= $_FILES['cl_logo']['tmp_name'];
$err = $_FILES['cl_logo']['error'];
if(($type="image/jpeg")||($type="image/gif")){
if($err>0){
echo "Error in file";
}
else{
$target_path = "images/";
$target_path = $target_path.$name;
if(move_uploaded_file($tmp,$target_path)){
echo "success";
}
else{
echo "failure";
}
}
return $target_path;
}
else{
echo "invalid File";
}
}
function
admin_list($id,$cl_name,$cl_place,$cl_site,$cl_logo,$cl_category){
$pagenum= $_GET['pagenum'];
$display_list = "";
$display_list .= "<form method='post'><table align='center'
border='1' cellpadding='8' cellspacing='2' width='700'>
<tr>
<td width='100%' align='center' colspan='8'>
<h3>list College information</h3>
</td>
</tr>
<tr>
<td width='5%' align='center'>ID</td><td width='10%'
align='center'>Name</td><td width='10%'
align='center'>Place</td><td width='10%'
align='center'>Site</td><td width='25%'
align='center'>Logo</td><td width='15%'
align='center'>category</td><td width='15%'
align='center'>DELETE</td><td width='10%'
align='center'>UPDATE</td>
</tr>
";
$pagenum = $_GET['pagenum']>0?$_GET['pagenum']:0;
if($id!=0){
echo "sekar";
$update = "update collegeinformation set
cl_name='$cl_name', cl_place='$cl_place',cl_site='$cl_site'
where id='$id'";
$up = mysql_query($update);
}
$select = "select
id,cl_name,cl_place,cl_site,cl_logo,cl_category from
collegeinformation";
$result = mysql_query($select);
while($res = mysql_fetch_array($result)){
$display_list .="<tr>
<td width='5%' align='center'>$res[0]</td><td width='10%'
align='center'>$res[1]</td><td width='10%'
align='center'>$res[2]</td><td width='10%'
align='center'>$res[3]</td><td width='25%'
align='center'>$res[4]</td><td width='15%'
align='center'>$res[5]</td><td width='15%' align='center'><a
href='admin.php?type=del&id=$res[0]&url=$res[5]'>DELETE</a></td><td
width='10%' align='center'><a
href='admin.php?type=update&id=$res[0]'>UPDATE</a></td>
</tr>";
}
$display_list .= "</table></form>";
echo $display_list;
}
function admin_delete(){
$id = $_GET['id'];
$url = unlink($_GET['url']);
$delete = "delete from collegeinformation where id ='$id'";
$result = mysql_query($delete);
if($result){
echo "1 record deleted";
}
else{
echo "Not deleted";
}
}
function admin_update(){
$id = $_GET['id'];
$select = "select id, cl_name, cl_place, cl_site from
collegeinformation where id='$id'";
$result = mysql_query($select);
while($res = mysql_fetch_array($result)){
$display_update .= "<form method='post' action=''
enctype='multipart/form-data'>
<table align='center' border='1' cellpadding='10'
cellspacing='5' width='700'>
<tr>
<td width='100%' align='center' colspan='3'><h3>College
information</h3></td>
</tr>
<tr>
<td width='40%' align='center'>College Name</td>
<td width='10%' align='center'>:</td>
<td width='50%' align='center'><input type='text'
name='cl_name' value='$res[1]'></td>
</tr>
<tr>
<td width='40%' align='center'>College Place</td>
<td width='10%' align='center'>:</td>
<td width='50%' align='center'><input type='text'
name='cl_place' value='$res[2]'></td>
</tr>
<tr>
<td width='40%' align='center'>College site</td>
<td width='10%' align='center'>:</td>
<td width='50%' align='center'><input type='text'
name='cl_site' value='$res[3]'></td>
</tr>
<tr>
<td width='100%' align='center' colspan='3'><input
type='submit' name='submit' value='UPDATE'></td>
</tr>
</table></form>";
echo $display_update;
if($_POST['submit']=='UPDATE'){
admin_list($res[0],$_POST['cl_name'],$_POST['cl_place'],$_POST['cl_site'],$res[4],$res[5]);
}
}
}
?>
Is This Answer Correct ? | 1 Yes | 2 No |
Post New Answer View All Answers
Is python better than php?
How does cookies work in php?
How do you define a constant in php?
What are headers in php?
What does the expression exception::__tostring means?
When to use single quotes, double quotes, and backticks?
What are the features and advantages of object-oriented programming in php?
What is the main difference between asp net and php?
What does $globals means?
armstrong number by using php while number is given by the keyboard.?
Write a program in php to check whether a number is prime or not?
Why do we use polymorphism in php?
How can we get ip address of a client in php?
How error handling is being handled by php?
How do sessions work in php?