Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

how to store date to database

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


Please Help Members By Posting Answers For Below Questions

What is meant by pear in php? What is the purpose of it?

911


Which php framework is best?

927


What is the most common http method?

1014


Which are the best start and end tags to use?

953


Is php case sensitive?

854


What is the use of die in php?

919


What is cookie and session in php?

918


Tell me what does pear stands for?

1005


What is interface? Why it is used?

964


What are the special characters you need to escape in single-quoted stings?

877


Difference between $message vs. $$Message in php.

945


Why session timeout is important?

1052


What are headers in php?

907


What is the basic syntax of Php?

1085


Explain mysql_error().

931