Update Record in php

 Update simple Record

if(isset($_POST[“update”]))
{
$rid = $_POST[‘id’];
$finame = $_POST[“fname”];
$query1 = “UPDATE users SET FirstName= ‘”.$_POST[fname].”‘, LastName= ‘”.$_POST[lname].”‘, Mobn= ‘”.$_POST[mobile].”‘, Email='”.$_POST[email].”‘ WHERE  Id='”.$rid.”‘”;   // Update Query
$up = mysql_query($query1,$con);
if($up)
{

die(“location.href = ‘SearchandUpdate.php'”);  //if header Function not then use die function.  this use redirect another page.

//header function – header(‘Location:SearchandUpdate.php’); same use die function.

}
else
{
echo “Error : Data not Updated !!!”;    //Error  message.
}
}

Advertisements

multiple div show and hide through database using dropdown list

$con = mysql_connect(“localhost”,”root”,””) or die(“mysql conn. error”);
mysql_select_db(‘databasename’) or die(“mysql conn. error”); // database connection

if(isset($_GET[‘Name’]))  //get  value through URL
{
$name = $_GET[‘Name’];
$query = “select * from cad where Name = ‘”.$name.”‘”;
$qu = mysql_query($query, $con);
while($res= mysql_fetch_array($qu))
{
if($res[‘ptype’] == ‘Half Yearly Payment’)
{

$Name = $res[“Name”];
$ptype = $res[“ptype”];
}
else if($res[‘ptype’] == ‘Monthly Payment’)
{

$Name = $res[“Name”];
$ptype = $res[“ptype”];

}
else if($res[‘ptype’]==’Quarterly Payment’)
{

$Name = $res[“Name”];
$ptype = $res[“ptype”];
}
else
{
$Name = $res[“Name”];

$ptype = $res[“ptype”];
}
}
}

// html code

<select class=”drop” id=”payment” name=”ptype” >
<option  id=”S_0″ value=”Monthly Payment”>Monthly Payment</option>
<option  id=”S_1″ value=”Quarterly Payment”>Quarterly Payment</option>
<option  id=”S_2″ value=”Half Yearly Payment”>Half Yearly Payment</option>
<option  id=”S_3″ value=”Yearly Payment”>Yearly Payment</option>
</select>

// multiple div show and hide php code

if($res[‘ptype’]== ‘Monthly Payment’)

{

  echo  $Name;    

   echo $ptype;

}

if($res[‘ptype’]== ‘Quarterly Payment’)

{

  echo  $Name;    

   echo $ptype;

}

if($res[‘ptype’]== ‘Half Yearly Payment’)

{

  echo  $Name;    

   echo $ptype;

}

if($res[‘ptype’]== ‘Yearly Payment’)

{

  echo  $Name;    

   echo $ptype;

}

Simple Login code php development

$con = mysql_connect(“localhost”,”root”,””) or die(“mysql conn. error”);
mysql_select_db(‘databasename’) or die(“mysql conn. error”); // database connection

// login  page code

if(isset($_POST[“Button”]))

{

$aidd  = $_POST[“Id”];  // get textbox value
$apass = $_POST[“pass”]; // get textbox value
$query = “select * from TableName where id =  ‘$aidd’ and Password = ‘$apass'”;  //sql query
$res = mysql_query($query ,$con); //execute query
if(mysql_num_rows($res) == 1)
{
$_SESSION[‘aid’] =  $aidd;
$_SESSION[‘apass’] = $apass;
header(‘Location:login.php’);   //redirect another page
}
else
{
echo “Error : Please Enter Correct password”;    // error message
}
}