在RedBean中更新

I am creating a Data Entry system. Now I am able to add data from a form. But update does not work.Instead when I try to update it adds another entry.

This is my add.php.

<?php
require 'rb.php';
R::setup( 'mysql:host=localhost:3306;dbname=employee',
        'root', '' );
$emp = R::dispense( 'emp' );
$emp->emp_no=$_GET['empno'];
$emp->empname =$_GET['empname'];
$emp->fathername =$_GET['fathername']; 
$emp->sex=$_GET['sex'];
$emp->designation =$_GET['designation']; 
$emp->department =$_GET['department']; 
$emp->dob =$_GET['dob'];
$emp->dor =$_GET['dor'];
$emp->doa =$_GET['doa'];
$emp->serviceStatus =$_GET['serviceStatus']; 
$emp->address =$_GET['address'];
$emp->pymtmode =$_GET['pymtmode'];
$emp->bank_code =$_GET['bank_code'];
$emp->acc_no =$_GET['acc_no'];
$emp->scale =$_GET['scale'];
$emp->basic =$_GET['basic'];



R::store( $emp );

?>

Here is my update.php. What is wrong in this.

<?php
require 'rb.php';
R::setup( 'mysql:host=localhost:3306;dbname=employee',
        'root', '' );
$emp = R::load('emp', $empno);
$emp->emp_no=$_GET['empno'];
$emp->empname =$_GET['empname'];
$emp->fathername =$_GET['fathername']; 
$emp->sex=$_GET['sex'];
$emp->designation =$_GET['designation']; 
$emp->department =$_GET['department']; 
$emp->dob =$_GET['dob'];
$emp->dor =$_GET['dor'];
$emp->doa =$_GET['doa'];
$emp->serviceStatus =$_GET['serviceStatus']; 
$emp->address =$_GET['address'];
$emp->pymtmode =$_GET['pymtmode'];
$emp->bank_code =$_GET['bank_code'];
$emp->acc_no =$_GET['acc_no'];
$emp->scale =$_GET['scale'];
$emp->basic =$_GET['basic'];



R::store( $emp );

?>

Here is a link to the screenshot of mysql console

http://i.stack.imgur.com/b9jcg.jpg

I think you are using $empno before you set it and you're not loading the existing row for updating.

$emp = R::load('emp', $empno);

Should be

$emp = R::load('emp', $_GET['empno']);

On your update.php file, you have the following line: $emp = R::load('emp', $empno);

But $empno is nowhere defined on your update.php file. Take the ID of the record you want to update and assign it to the variable this way:

$empno = $_GET['empno'];

Put it at the beginning of your file.

Thanks for answering guys...Andrew R and Muhammad...Here is the code that works:

 <?php
require 'rb.php';
R::setup( 'mysql:host=localhost:3306;dbname=employee',
        'root', '' );
$empno = $_GET['empno'];
$emp = R::findOne('emp','emp_no=?',[$empno]);
$emp->emp_no=$_GET['empno'];
$emp->empname =$_GET['empname'];
$emp->fathername =$_GET['fathername']; 
$emp->sex=$_GET['sex'];
$emp->designation =$_GET['designation']; 
$emp->department =$_GET['department']; 
$emp->dob =$_GET['dob'];
$emp->dor =$_GET['dor'];
$emp->doa =$_GET['doa'];
$emp->serviceStatus =$_GET['serviceStatus']; 
$emp->address =$_GET['address'];
$emp->pymtmode =$_GET['pymtmode'];
$emp->bank_code =$_GET['bank_code'];
$emp->acc_no =$_GET['acc_no'];
$emp->scale =$_GET['scale'];
$emp->basic =$_GET['basic'];



R::store( $emp );

?>

</div>