これが私のコードです。データベースフィールドを更新したいのですが、エラーに直面しています.クエリデータの投稿は正しいのですが、なぜID = 0を印刷します.dbテーブルに大文字のIDがありますが、なぜ私がajax経由で更新したい問題なのか答えてください. 1UPDATE form
SET st_name
= 'hello', st_class
= 'update', st_address
= 'SystemConfig' WHERE ID
= 0 id が 0 であるため、データを更新しないのはなぜですか?
これがビュー内の私のajx関数です
<script>
$(document).ready(function() {
$(".Update").fancybox({
'transitionIn' : 'fade',
'transitionOut' : 'fade',
'speedIn' : 600,
'speedOut' : 200,
'overlayShow' : false
});
var Id = $(this).attr("id");
var parent = $(this).parent();
$("#updateform").bind("submit", function() {
$.ajax({
type : "POST",
cache : false,
url : "http://localhost/testproj/index.php/form/update",
data : $(this).serializeArray(),
success:function(data){
$.fancybox(data);
}
});
return false;
});
});
**VIEW**
</head>
<body>
<form id="Form" action="" method="post"
name="Form" onsubmit="return submitForm();" ;>
<br></br>
<table id = "fixedme" border ='0' cellpadding='0' cellspacing='0'>
<tr>
<td>Message: </td>
<td><input id='Name' name='Name' type='text' size='20' maxlength='50'/></td>
<td>Action</td>
<td><select name="action" id="action">
<option value="">--Select--</option>
<option value="insert">Insert</option>
<option value="update">Update</option>
<option value="delete">Delete</option></select></td>
<td>Action By</td>
<td><select name="actionBy" id="actionBy">
<option value="">--Select--</option>
<option value="Transaction">Transaction</option>
<option value="ManageOperation">Manage Operation</option>
<option value="FeeRate">Fee Rate</option>
<option value="SystemConfig">System Config</option>
<option value="Compliance">Compliance</option>
<option value="Usermanagement">User Management</option>
<option value="OnlineSenderAdmin">Online Sender Admin</option>
</select></td>
</tr>
<tr><td collspan='2'><input type="submit" name="submit" id="submit" value="submit" class="submit"/></td></tr></table>
</form>
</div>
<div style="display:none;" id = "updateDialog" >
<form id="updateform" action="" method="post">
<p><h1 align="center">Update</h1></p>
<p>
<label>Message:</label>
<input type="text" id="name" name="name" />
</p>
<p>
<label>Action On:</label>
<select name="action" id="action">
<option value="">--Select--</option>
<option value="insert">Insert</option>
<option value="update">Update</option>
<option value="delete">Delete</option></select>
</p>
<p>
<label>ActionBy:</label>
<select name="actionBy" id="actionBy">
<option value="">--Select--</option>
<option value="Transaction">Transaction</option>
<option value="ManageOperation">Manage Operation</option>
<option value="FeeRate">Fee Rate</option>
<option value="SystemConfig">System Config</option>
<option value="Compliance">Compliance</option>
<option value="Usermanagement">User Management</option>
<option value="OnlineSenderAdmin">Online Sender Admin</option>
</select>
</p>
<p><input type="submit" name="save"
id="save" value="save" class="save"/>
<input type="submit" name="Close"
id="Close" value="Close" class="submit"/>
</form>
</div>
<div id="message">
<form id="myForm" action="" method="" name="myForm" class="myForm"><br></br>
<table id = "fixedme" border ='1' cellpadding='0' cellspacing='0'>
<tr>
<th>ID: </th>
<th>Message: </th>
<th>Action On:</th>
<th>ActionBy </th>
<th>Actions </th>
</tr>
<tbody>
<?php
if($result!="")
{
foreach($result as $rows){ ?>
<tr id="ide"><td><span><?php echo $ID=$rows->ID;?></span></td>
<td><span><?php echo $name=$rows->st_name;?></span></td>
<td><span><?php echo $action=$rows->st_address; ?></span></td>
<td><span><?php echo $actionby=$rows->st_class; ?> </span></td>
<td><a href="#" class="delete" id="<?php echo $ID=$rows->ID;?>"
name="delete" >Delete</a>
<a href="#updateDialog" class="Update" id="<?php echo $ID=$rows->ID ;?>"
name="Update">Update</a>
</td></tr>
<?php }}?>
</tbody>
</table>
</form>
</div>
</div>
</div>
</body>
</html>
**MODEL**
public function submit_updated_data($id,$data)
{
$this->load->database();
$this->db->where('ID', $id);
$query2 =$this->db->update( 'form', $data);
}
**CONTROLLER**
public function update()
{
$id=$this->input->post('ID');
$name=$this->input->post('name');
$action= $this->input->post('action');
$actionBy = $this->input->post('actionBy');
$data = array(
'st_name' => $name,
'st_class' =>$action,
'st_address'=>$actionBy
);
$this->form_model->submit_updated_data($id,$data);
$this->index();
}
1UPDATE `form` SET `st_name` = 'hello', `st_class` = 'update', `st_address` = 'SystemConfig' WHERE `ID` = 0