1
這裏是我的代碼我想更新數據庫字段,但面臨error.i打印查詢數據發佈是正確的,但爲什麼ID = 0我有數據庫表中的資本ID,但爲什麼請回答我什麼是問題我想通過ajax更新。 1UPDATE form
SET st_name
= '你好',st_class
= '更新',st_address
= 'SystemConfig' WHERE ID
= 0 因爲ID爲0,這就是爲什麼它不更新數據,但是,爲什麼呢?Codeigniter更新數據庫字段錯誤
這是我考慮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
型號和控制器也在上面的代碼中需要回答。 –
我想通過ajax –
更新如何通過id?但它顯示id爲0爲什麼?如果我在模型查詢中硬編碼該id,那麼它會更新該id的數據。在查詢或ajax函數中有問題嗎? –