Insert Data into MySQL database using PHP


PHP classes

<?php

session_start();
include(“connection.php”);
$emailid = $_SESSION[‘uid1’];
$fecth_value=”select * from tablename where Email=’$emailid'”;
$fecth_main_data=mysql_query($fecth_value);
$main_data=mysql_fetch_array($fecth_main_data);
if(empty($emailid))
{
 unset($_SESSION[‘uid1’]);
header(‘location:../index.php’);
}

if($_REQUEST[‘Insert’])
{
$dtime=$_REQUEST[‘txtdate’];
$grate=$_REQUEST[‘txtgoldrate’];
$srate=$_REQUEST[‘txtsilverrate’];
$drate=$_REQUEST[‘txtdiamondrate’];
if(empty($dtime)||empty($grate) || empty($srate))
{
$message=”please enter date,goldrate and silverrate”;
}
else
{
include(‘connection.php’);
$query=”Insert into table(col1,col2,col3,col3) values(‘”.$dtime.”‘,'”.$grate.”‘,'”.$srate.”‘,'”.$drate.”‘)”;
$result=mysql_query($query);
if($result > 0)
{
$message=”Data Saved Succesfully”;
header(‘location:index.php’);
}
else
{
$message=”Sorry Data not saved”;
}
}
}

if($_REQUEST[‘Update’])
{
$dtime=$_REQUEST[‘txtdate’];
$grate=$_REQUEST[‘txtgoldrate’];
$srate=$_REQUEST[‘txtsilverrate’];
$drate=$_REQUEST[‘txtdiamondrate’];
if(empty($dtime)||empty($grate) || empty($srate))
{
$message=”please enter date,goldrate and silverrate”;
}
else
{
include(‘connection.php’);
$query=”Update table set col1='”.$dtime.”‘,col2='”.$grate.”‘,col3='”.$srate.”‘,col4='”.$drate.”‘ where Sno=”.$_GET[‘primaryno’].””;
$result=mysql_query($query);
if($result > 0)
{
$message=”Data update Succesfully”;
header(‘location:index.php’);
}
else
{
$message=”Sorry Data not update succesfully”;
}
}
}

?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Update Todays Rate</title>
<link href=”../styles.css” rel=”stylesheet” type=”text/css”/>
</head>
<body>
<?php include(‘header.php’); ?>




<div id=”rightdiv”>
<form method=”post” action=””>
<table  style=”border:double #0000FF 2px; margin-top:10px;”>

View original post 65 more words

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s