In each row of a table, I have an “insert” link. When a user clicks this link, a popup window appears containing a form. When the user clicks the “save” button for the form, the form update works only for the first row of the parent table. It takes only the first row ID.
<!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>
</style>-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Popup contact form using only CSS - Demo | CodingCrazy</title>
<link href="<?php echo base_url();?>assets/css/styleform.css" rel="stylesheet" type="text/css"/>
<link href='http://fonts.googleapis.com/css?family=Electrolize' rel='stylesheet' type='text/css' />
<!--CC-->
<link rel="stylesheet" href="<?php echo base_url();?>assets/css/fonts.css"/>
</head>
</body>
</html>
<!--<link rel="stylesheet" href="<?php // echo base_url();?>assets/css/special.css" type="text/css" />-->
<div class="bal" style="margin-left: 627px;
padding: 15px;">
Balance Amount:<input type="text" name="bal">
<?php echo form_open('money_c/addrow')?>
<input type="submit" style="padding:7px;" name="sub" value="add row">
<?php echo form_close();?></div>
<table border="1">
<tr>
<th>Date</th>
<th>Description</th>
<th>Category</th>
<th>Debit</th>
<th>Credit</th>
<th>Bal.AMT</th>
<th>Insert</th>
<th> EDit/Delete</th></tr>
<?php foreach($query2 as $row)
{
$date=$row->date;
$desc=$row->description;
$credit=$row->credit;
$deb=$row->debit;
$bal=$row->bal;
$cat=$row->category;
$id=$row->id;
?>
<tr><td><?php echo $date;?></td>
<td><?php echo $desc;?></td>
<td><?php echo $credit;?></td>
<td><?php echo $deb;?></td>
<td><?php echo $bal;?></td>
<td><?php echo $cat;?></td>
<td><a href="#pop" >Insert<div id="pop" class="box">
<?php
?>
<!--<form action="" method="post" class="smart-green">-->
<div class="smart-green">
<?php
echo form_open('money_c/manualupdatesave/'.$id)?>///here updation happens only for first row id;
<h1>
<span>Please fill all the texts in the fields.</span>
</h1>
<label>
<span>Date:</span>
<input type="date" name="dat" />
</label>
<label>
<span>Description:</span>
<input name="desc" type="text" />
</label>
<label>
<span>Category:</span><select name="selection">
<?php foreach($query1 as $row1)
{
$cat=$row1->category;
?>
<!--<option value="Job Inquiry">Job Inquiry</option>-->
<option value="<?php echo $cat;?>"><?php echo$cat;?></option>
<?php
}
?>
</select>
</label>
<label>
<span>Debit:</span>
<input type="text" name="deb"></input>
</label>
<label>
<span>Credit:</span>
<input type="text" name="credit"></input>
</label>
<label>
<span> </span>
<input type="submit" style="margin-top:12px" class="button" style="background-color: #004e98;"value="Send" />
</label>
</div>
<?php echo form_close();?>
<!--</form>-->
<div id="close">
<td><a href="<?php echo site_url('money_c/manualdelete/'.$id);?>"><img src="<?php echo base_url();?>assets/images/del.jpg" width="60" height="40"></a></td>
</tr>
<?php
}
?></table>
</tbody>
</table>
My controller:
money_c
function manualupdatesave($id)
{
$a=$this->input->post('dat');
$b=$this->input->post('desc');
$c=$this->input->post('cat');
$d=$this->input->post('deb');
$e=$this->input->post('credit');
$this->money_m->transaction($a,$b,$c,$d,$e,$id);
$this->load->view('header');
$result['query2'] = $this->money_m->selecttrans();
$this->load->view('manualupdate',$result);
$this->load->view('footer');
}
view page: manualupdate.php
:
<!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>
</style>-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Popup contact form using only CSS - Demo | CodingCrazy</title>
<link href="<?php echo base_url();?>assets/css/styleform.css" rel="stylesheet" type="text/css"/>
<link href='http://fonts.googleapis.com/css?family=Electrolize' rel='stylesheet' type='text/css' />
<!--CC-->
<link rel="stylesheet" href="<?php echo base_url();?>assets/css/fonts.css"/>
</head>
<!--<link rel="stylesheet" href="<?php // echo base_url();?>assets/css/special.css" type="text/css" />-->
<div class="bal" style="margin-left: 627px;
padding: 15px;">
Balance Amount:<input type="text" name="bal">
<?php echo form_open('money_c/addrow')?>
<input type="submit" style="padding:7px;" name="sub" value="add row">
<?php echo form_close();?></div>
<table border="1">
<tr>
<th>Date</th>
<th>Description</th>
<th>Category</th>
<th>Debit</th>
<th>Credit</th>
<th>Bal.AMT</th>
<th>Insert</th>
<th> EDit/Delete</th></tr>
<?php foreach($query2 as $row)
{
$date=$row->date;
$desc=$row->description;
$credit=$row->credit;
$deb=$row->debit;
$bal=$row->bal;
$cat=$row->category;
$id=$row->id;
?>
<tr><td><?php echo $date;?></td>
<td><?php echo $desc;?></td>
<td><?php echo $credit;?></td>
<td><?php echo $deb;?></td>
<td><?php echo $bal;?></td>
<td><?php echo $cat;?></td>
<td><a href="#pop" >Insert<div id="pop" class="box">
<?php
?>
<!--<form action="" method="post" class="smart-green">-->
<div class="smart-green">
<?php
echo form_open('money_c/manualupdatesave/'.$id)?>
<h1>
<span>Please fill all the texts in the fields.</span>
</h1>
<label>
<span>Date:</span>
<input type="date" name="dat" />
</label>
<label>
<span>Description:</span>
<input name="desc" type="text" />
</label>
<label>
<span>Category:</span><select name="selection">
<?php foreach($query1 as $row1)
{
$cat=$row1->category;
?>
<!--<option value="Job Inquiry">Job Inquiry</option>-->
<option value="<?php echo $cat;?>"><?php echo$cat;?></option>
<?php
}
?>
</select>
</label>
<label>
<span>Debit:</span>
<input type="text" name="deb"></input>
</label>
<label>
<span>Credit:</span>
<input type="text" name="credit"></input>
</label>
<label>
<span> </span>
<input type="submit" style="margin-top:12px" class="button" style="background-color: #004e98;"value="Send" />
</label>
</div>
<?php echo form_close();?>
<!--</form>-->
<div id="close">
<td><a href="<?php echo site_url('money_c/manualdelete/'.$id);?>"><img src="<?php echo base_url();?>assets/images/del.jpg" width="60" height="40"></a></td>
</tr>
<?php
}
?></table>
</tbody>
</table>
My popup form:
<?php
echo form_open('money_c/manualupdatesave/'.$id)?>
<h1>
<span>Please fill all the texts in the fields.</span>
</h1>
<label>
<span>Date:</span>
<input type="date" name="dat" />
</label>
<label>
<span>Description:</span>
<input name="desc" type="text" />
</label>
<label>
<span>Category:</span><select name="selection">
<?php foreach($query1 as $row1)
{
$cat=$row1->category;
?>
<!--<option value="Job Inquiry">Job Inquiry</option>-->
<option value="<?php echo $cat;?>"><?php echo$cat;?></option>
<?php
}
?>
</select>
</label>
<label>
<span>Debit:</span>
<input type="text" name="deb"></input>
</label>
<label>
<span>Credit:</span>
<input type="text" name="credit"></input>
</label>
<label>
<span> </span>
<input type="submit" style="margin-top:12px" class="button" style="background-color: #004e98;"value="Send" />
</label>
</div>
<?php echo form_close();?>