hello world,

myself kishan kumar, iam new to web developing...my task is interrelated to edit,save & cancel....which is similar to edit button in shine.com...Iam doing in php language.the work is when user clicks on edit button he must be able to edit and after on editing he can save it i.e updation in database.....(when user clicks on edit button, save and cancel buttons should come and moreover the save and cancel buttons should occur in same page.......thanks..my php code is

<?php 

mysql_connect("localhost","root","")or die (mysql_error ());
mysql_select_db("edit")or die (mysql_error ());

$eduser=$_POST['user'];
$edpassword=$_POST['password'];

$sql="SELECT * FROM members WHERE uname='".$eduser."' and password='".$edpassword."'";
$result=mysql_query($sql);
while($info=mysql_fetch_array($result))
{
if($eduser=$edpassword)
{
?>
<p>
<table width="45%" border="1" cellspacing="0" cellpadding="0">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
<form id="fn">
    <div>
    <input class="edit" type="button" value="Edit" />
    <input class="save" type="button" value="Save" /> 
    <input class="cancel" type="button" value="Cancel" />
    </div>
   <tr>
 <td><input type="text"  value="<?php echo $info['fname'];?>" /></td>
  <?php echo "<p></p>"; ?>

  <td><input type="text" value="<?php echo $info['lname'];?>" /></td>
      <?php echo "<p></p>"; ?>

 <td><input type="text" value="<?php echo $info['email'];?>"  /></td>
  <?php echo "<p></p>"; ?>
  </form>
  </tr>
  <?php 
  }
else
{
echo "somewhere mistake";
}
}
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<style type='text/css'>
    .save, .cancel {
display:none;
}
</style>
 <script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
$('#fn').hide();
$('.edit').click(function() {
    $(this).hide();


    $(this).siblings('.save, .cancel').show();
    $('#fn').show();
});

$('.cancel').click(function() {
    $(this).siblings('.edit').show();
    $(this).siblings('.save').hide();
    $(this).hide();
    $('#fn').hide();  


});
$('.save').click(function() {
    $(this).siblings('.edit').show();
    $(this).siblings('.cancel').hide();
    $(this).hide();
    $('#fn').hide();

});

});//]]>  

</script>
</head>
<body>
</body>
</html>

and my database is -- phpMyAdmin SQL Dump
-- version 3.4.5

-- Host: localhost
-- Generation Time: May 21, 2014 at 11:04 AM
-- Server version: 5.5.16
-- PHP Version: 5.3.8

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";

/!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/
!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;
/
!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /;
/
!40101 SET NAMES utf8 */;

--

-- Database: edit

-- --------------------------------------------------------

--

-- Table structure for table members

CREATE TABLE IF NOT EXISTS members (
id int(11) NOT NULL AUTO_INCREMENT,
fname varchar(100) NOT NULL,
lname varchar(100) NOT NULL,
email varchar(50) NOT NULL,
uname varchar(255) NOT NULL,
password varchar(20) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

--

-- Dumping data for table members

INSERT INTO members (id, fname, lname, email, uname, password) VALUES
(1, '1', '1', '1', 'kishan', 'kumar'),
(2, 'kishan', 'kumar', 'kishankumar1220@yaho.com', 'madhava', 'nakrekal'),
(3, 'ravitgh6yuj5', 'uyttyyyytyt5ju5475', 'kiran@hotmail.com', 'sripriya', 'nalg');

/!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/
!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS /;
/
!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

if any one is not understanding mu question can ask in comments...

This is PHP forum, not Javascript. You can post your problem in Javascript / DHTML forum.

ya dude...but updation must be done through php only

But, your question doesn't state any PHP process. You just asked to display / hide 'Save/Cancel' button upon 'Edit' button clicked.

actually i solved that showing edit/save/cancel resolution...
but when i edit the page and when i click save button it should update the database(this all should be done when user logins....) this is my code..(i getting mistakes)thanks

<?php 

mysql_connect("localhost","root","")or die (mysql_error ());
mysql_select_db("edit")or die (mysql_error ());

$first=isset($_POST['first']);
$last=isset($_POST['last']);
$emai=isset($_POST['ema']);


$eduser=$_POST['user'];
$edpassword=$_POST['password'];

$sql="SELECT * FROM members WHERE uname='".$eduser."' and password='".$edpassword."'";
$result=mysql_query($sql);
while($info=mysql_fetch_array($result))
{
if($eduser=$edpassword)
{
?>
<div id="output">
Firstname:<?php echo $info['fname'];?><br>
Lastname:<?php echo $info['lname'];?><br>
E-mail:<?php echo $info['email'];?><br>
</div>

<div id="input">
<form method="post" action="krishna.php">
Firstname:<input type="text" name="first" value="<?php echo $info['fname'];?>"   /><br>
Lastname:<input type="text"  name="last"  value="<?php echo $info['lname'];?>"   /><br>
E-mail:<input type="text"  name="ema"    value="<?php echo $info['email'];?>"   /><br>
<input type="hidden" name="update" value="update">
</form>
</div>

  <?php 
  }
else
{
echo "somewhere mistake";
}
}

$sql="update members set fname ='".$first."', lname='".$last."', email='".$emai."'  WHERE uname='".$eduser."' ";
$ap=mysql_query($sql);
if($ap)
{
echo "sucesfully updated";
}
else
{
echo "not";
}
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<style type='text/css'>
    .save, .cancel {
display:none;
}
</style>
 <script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
$('#input').hide();


$('.edit').click(function() {
    $(this).hide();
    $('#input').show();
    $('#output').hide();
   $(this).siblings('.save, .cancel').show();
});

$('.cancel').click(function() {
    $(this).siblings('.edit').show();
    $(this).siblings('.save').hide();
    $(this).hide();
    $('#input').hide();
    $('#output').show(); 

});

$('.save').click(function() {
    $(this).siblings('.edit').show();

    $(this).siblings('.cancel').hide();
    $(this).hide();
    $('#input').hide();
    $('#output').show();

});

});//]]>  
</script>
</head>
<body>

    <input class="edit" type="button" value="Edit" />
    <input class="save" type="button" value="Save" /> 
    <input class="cancel" type="button" value="Cancel" />
</body>
</html>
and database is:

Databasename: edit

Table structure for table members

CREATE TABLE IF NOT EXISTS members (
fname varchar(100) NOT NULL,
lname varchar(100) NOT NULL,
email varchar(50) NOT NULL,
uname varchar(255) NOT NULL,
password varchar(20) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

--

-- Dumping data for table members

INSERT INTO members (fname, lname, email, uname, password) VALUES
('kishan', 'kumar', 'kishankumar1220@yaho.com', 'madhava', 'nakrekal'),
('ravi', 'chandra', 'kiran@hotmail.com', 'sripriya', 'nalg');

If anyone is having doubts can comment....

Some mistakes:

$eduser=$_POST['user'];
$edpassword=$_POST['password'];

There is no 'user' and 'password' fields in your form or perhaps, it came from other page ?

$first=isset($_POST['first']);
$last=isset($_POST['last']);
$emai=isset($_POST['ema']);

isset() returns boolean (true / false), not actual values of your first, last, ema fields from the form. The condition should look like this and update query should run inside:

if(isset($_POST['first']) && isset($_POST['last']) && isset($_POST['ema'])) {
    // do your stuff here, validate data, sanitize and run update query
    $first_name = $_POST['first'];
    $last_name  = $_POST['last'];
    $email      = $_POST['ema'];
}

HTML is also invalid, the form is outside of <html> tag. Hopes it help.

ya user and password came from another page....

actually iam not getting where to start the <form> tag and close it...my text fields are at line no 29,30,31

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.