私はこのような宿題をしたい:
データベースには画像のリストがあり、各画像には ID、パス、コメントがあります。そして、各画像のテキスト入力を実現し、コメントを書き込んでデータベースに更新したいと考えています。
データベースの table:images には、id、パス、コメントが含まれています。
コードは次のとおりです。
イメージコントローラー:
<?php
class Image extends CI_Controller {
function comment()
{
$data=array(
'id'=>$this->input->post('id'),
'path'=>$this->imageModel->get($this->input->post('id'))->path,
'comment'=>$this-input->post('comment')
);
$result=$this->imageModel->Update($data);
}
}
画像モデル:
<?php
class ImageModel extends CI_Model {
private $table = 'images';
function ImageModel()
{
// Call the Model constructor
parent::__construct();
}
function get($id)
{
$query = $this->db->get_where( $this->table, array('id' => $id) );
return $query->result();
}
function Update($news){
$this->db->where('id',$news->id);
$this->db->update($this->table,$news);
}
}
ビュー:
img src="<?php echo base_url();?>/<?php echo $item->path;?>" title ="<?php echo $item->path;?>" rel="<?php echo $item->comment;?>"
class ="tips" width=200 height=200></img>
<span><?php echo $item->id;?> :<input type="text" id="<?php echo $item->id;?>"/>
<input type="submit" id="send<?php echo $item->id;?>"
<script type='text/javascript'>
window.addEvent("domready",function(){
$("send<?php echo $item->id;?>").addEvent("click",function(){
if($("<?php echo $item->id;?>").value==''){
alert('Please entre your comment!');
return;
}
var myRequest = new Request({
method: 'post',
url: 'http://localhost/public_html/CodeIgniter/index.php/image/comment',
onSuccess: function(responseText){
alert(responseText);
},
onFailure: function(){
alert( 'Erreur!');
}
});
myRequest.send('id='+<?php echo $item->id;?> +'&comment='+$("<?php echo $item->id;?>").value);
});
});
</script>
問題は、テキストに何かを書いて送信をクリックすると、常に「Erreur!」と表示されることです。私はそれに2日間費やしました。誰か助けてくれますか???