Php 使用表单上载字段编辑注册表
我有一个应用程序,我创建了一个文件上传注册。好的,文件上传和创建的注册都很好 我希望当用户放置一个文件时,它会进行更新。如果不是,则不要更新包含文件路径的字段 但是,我需要编辑这个注册表。编辑时,“我的文件上载”显示错误: 错误:SQLSTATE[42S22]:找不到列:“字段列表”中的1054未知列“数组” SQL查询:UPDATEPhp 使用表单上载字段编辑注册表,php,file-upload,cakephp-2.0,Php,File Upload,Cakephp 2.0,我有一个应用程序,我创建了一个文件上传注册。好的,文件上传和创建的注册都很好 我希望当用户放置一个文件时,它会进行更新。如果不是,则不要更新包含文件路径的字段 但是,我需要编辑这个注册表。编辑时,“我的文件上载”显示错误: 错误:SQLSTATE[42S22]:找不到列:“字段列表”中的1054未知列“数组” SQL查询:UPDATEsocietarioattorneysSETnome='teste editar',empresa='',Durth='',unidade='Energia',al
societario
attorneys
SETnome
='teste editar',empresa
='',Durth
='',unidade
='Energia',alcada
='Até10.000',validade
=/code>=/123111',arquivo
=数组,其中societario
律师
id
='83'
我的创建控制器:
if($this->request->is('post')){
$targetFolder = 'societario/app/webroot/uploads/'; // Relative to the root
$tempFile = $this->request->data['Attorney']['arquivo']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $this->request->data['Attorney']['arquivo']['name'];;
move_uploaded_file($tempFile,$targetFile);
$this->Attorney->saveAll($this->request->data, array('fieldList' => array('nome','empresa','filial','unidade','validade', 'alcada', 'status')));
$this->Attorney->updateAll(
array('arquivo' => "'".$this->request->data['Attorney']['arquivo']['name'] ."'",),
array('id' => $this->Attorney->id));
$this->Attorney->id = $id;
$this->set('poderes',$this->Attorney->Power->find('list', array('fields' => 'resumo')));
if ($this->request->is('get')) {
$this->request->data = $this->Attorney->read();
} else {
if ($this->Attorney->save($this->request->data, array('fieldList' => array('nome','empresa','filial','unidade','validade', 'alcada', 'status')))) {
if(!empty($this->request->data['Attorney']['arquivo']['name'])) {
$targetFolder = 'societario/app/webroot/uploads/'; // Relative to the root
$tempFile = $this->request->data['Attorney']['arquivo']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $this->request->data['Attorney']['arquivo']['name'];;
move_uploaded_file($tempFile,$targetFile);
$this->Attorney->updateAll(
array('arquivo' => "'".$this->request->data['Attorney']['arquivo']['name'] ."'",),
array('id' => $this->Attorney->id));
$this->Session->setFlash('procuração editada com sucesso!', 'default', array('class' => 'flash_sucess'));
$this->redirect(array('action' => 'usuarios'));
}
$this->Session->setFlash('Usuário editado com sucesso!', 'default', array('class' => 'flash_sucess'));
$this->redirect(array('action' => 'usuarios'));
}
}
我的编辑控制器:
if($this->request->is('post')){
$targetFolder = 'societario/app/webroot/uploads/'; // Relative to the root
$tempFile = $this->request->data['Attorney']['arquivo']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $this->request->data['Attorney']['arquivo']['name'];;
move_uploaded_file($tempFile,$targetFile);
$this->Attorney->saveAll($this->request->data, array('fieldList' => array('nome','empresa','filial','unidade','validade', 'alcada', 'status')));
$this->Attorney->updateAll(
array('arquivo' => "'".$this->request->data['Attorney']['arquivo']['name'] ."'",),
array('id' => $this->Attorney->id));
$this->Attorney->id = $id;
$this->set('poderes',$this->Attorney->Power->find('list', array('fields' => 'resumo')));
if ($this->request->is('get')) {
$this->request->data = $this->Attorney->read();
} else {
if ($this->Attorney->save($this->request->data, array('fieldList' => array('nome','empresa','filial','unidade','validade', 'alcada', 'status')))) {
if(!empty($this->request->data['Attorney']['arquivo']['name'])) {
$targetFolder = 'societario/app/webroot/uploads/'; // Relative to the root
$tempFile = $this->request->data['Attorney']['arquivo']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $this->request->data['Attorney']['arquivo']['name'];;
move_uploaded_file($tempFile,$targetFile);
$this->Attorney->updateAll(
array('arquivo' => "'".$this->request->data['Attorney']['arquivo']['name'] ."'",),
array('id' => $this->Attorney->id));
$this->Session->setFlash('procuração editada com sucesso!', 'default', array('class' => 'flash_sucess'));
$this->redirect(array('action' => 'usuarios'));
}
$this->Session->setFlash('Usuário editado com sucesso!', 'default', array('class' => 'flash_sucess'));
$this->redirect(array('action' => 'usuarios'));
}
}
编辑:修改了编辑控制器。答案如下。
$this->Attorney->id = $id;
$this->set('poderes',$this->Attorney->Power->find('list', array('fields' => 'resumo')));
if ($this->request->is('get')) {
$this->request->data = $this->Attorney->read();
} else {
if ($this->Attorney->save($this->request->data)) {
$this->Session->setFlash('Usuário editado com sucesso!', 'default', array('class' => 'flash_sucess'));
$this->redirect(array('action' => 'usuarios'));
}
}
它认为数组是一个字段。。。所以,如果你真的想保存“数组”,那么把它放在单引号里。否则我想你忘了美元
编辑-我想我会在你的更新声明中提到这一点。我找到了解决方案!!谢谢 我的编辑控制器:
if($this->request->is('post')){
$targetFolder = 'societario/app/webroot/uploads/'; // Relative to the root
$tempFile = $this->request->data['Attorney']['arquivo']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $this->request->data['Attorney']['arquivo']['name'];;
move_uploaded_file($tempFile,$targetFile);
$this->Attorney->saveAll($this->request->data, array('fieldList' => array('nome','empresa','filial','unidade','validade', 'alcada', 'status')));
$this->Attorney->updateAll(
array('arquivo' => "'".$this->request->data['Attorney']['arquivo']['name'] ."'",),
array('id' => $this->Attorney->id));
$this->Attorney->id = $id;
$this->set('poderes',$this->Attorney->Power->find('list', array('fields' => 'resumo')));
if ($this->request->is('get')) {
$this->request->data = $this->Attorney->read();
} else {
if ($this->Attorney->save($this->request->data, array('fieldList' => array('nome','empresa','filial','unidade','validade', 'alcada', 'status')))) {
if(!empty($this->request->data['Attorney']['arquivo']['name'])) {
$targetFolder = 'societario/app/webroot/uploads/'; // Relative to the root
$tempFile = $this->request->data['Attorney']['arquivo']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $this->request->data['Attorney']['arquivo']['name'];;
move_uploaded_file($tempFile,$targetFile);
$this->Attorney->updateAll(
array('arquivo' => "'".$this->request->data['Attorney']['arquivo']['name'] ."'",),
array('id' => $this->Attorney->id));
$this->Session->setFlash('procuração editada com sucesso!', 'default', array('class' => 'flash_sucess'));
$this->redirect(array('action' => 'usuarios'));
}
$this->Session->setFlash('Usuário editado com sucesso!', 'default', array('class' => 'flash_sucess'));
$this->redirect(array('action' => 'usuarios'));
}
}
var\u dump($this->request->data['authority']['arquivo']['name'])
显示了什么?在创建或编辑时需要这个吗?因为您收到的错误消息在更新中…对不起。没有返回任何内容var\u dump
将始终打印某些内容-如果变量为空,它将显示该内容;否则它会把内容打印出来。我找到了解决办法。谢谢