gpt4 book ai didi

mysql - Joomla 3.1 数据库更新查询不起作用

转载 作者:行者123 更新时间:2023-11-30 01:14:22 24 4
gpt4 key购买 nike

最近我正在为 joomla 3.1 后端制作一个上传组件。基于How to Save Uploaded File's Name on Database我成功地将文件移动到硬盘上,但是我无法根据上面发布的帖子让更新查询正常工作。

我没有收到任何 SQL 错误并且保存有效,但不知何故忽略了数据库部分。

我真的希望我错过了一些明显的事情。 (顺便说一句,我不太了解 joomla 的查询方式)

phpmyadmin 中,以下查询有效:

UPDATE hmdq7_mysites_projects
SET project_file = 'test'
WHERE id IN (3);

我尝试了以下查询:

$id = JRequest::getVar('id');
$db =& JFactory::getDBO();
$sql = "UPDATE hmdq7_mysites_projects
SET project_file =' " . $filename. "'
WHERE id IN (".$id.");";
$db->setQuery($sql);
$db->query();
<小时/>
$colum = "project_file";
$id = JRequest::getVar('id');
$data = JRequest::getVar( 'jform', null, 'post', 'array' );
$data['project_file'] = strtolower( $file['name']['project_file'] );

$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->update('#__mysites_projects');
$query->set($column.' = '.$db->quote($data));
$query->where('id'.'='.$db->quote($id));
$db->setQuery($query);
$db->query();

这是当前代码:

class MysitesControllerProject extends JControllerForm
{

function __construct() {
$this->view_list = 'projects';
parent::__construct();
}

function save(){
// ---------------------------- Uploading the file ---------------------
// Neccesary libraries and variables
jimport( 'joomla.filesystem.folder' );
jimport('joomla.filesystem.file');

$path= JPATH_SITE . DS . "images";
// Create the gonewsleter folder if not exists in images folder
if ( !JFolder::exists(JPATH_SITE . "/images" ) ) {
JFactory::getApplication()->enqueueMessage( $path , 'blue');
}

// Get the file data array from the request.
$file = JRequest::getVar( 'jform', null, 'files', 'array' );

// Make the file name safe.
$filename = JFile::makeSafe($file['name']['project_file']);

// Move the uploaded file into a permanent location.
if ( $filename != '' ) {
// Make sure that the full file path is safe.
$filepath = JPath::clean( JPATH_SITE . "/images/" . $filename );

// Move the uploaded file.
JFile::upload( $file['tmp_name']['project_file'], $filepath );

$colum = "project_file";
$id = JRequest::getVar('id');
$data = JRequest::getVar( 'jform', null, 'post', 'array' );
$data['project_file'] = strtolower( $file['name']['project_file'] );

$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->update('#__mysites_projects');
$query->set($column.' = '.$db->quote($data));
$query->where('id'.'='.$db->quote($id));
$db->setQuery($query);
$db->query();


}

// ---------------------------- File Upload Ends ------------------------

JRequest::setVar('jform', $data );

return parent::save();
}

最佳答案

(OP在评论中回答。转换为社区维基答案。请参阅 Question with no answers, but issue solved in the comments (or extended in chat) )

OP 写道:

Solved: after reviewing the post update record in database using jdatabase I made up some fixed test values. It turns out the query is correct but $data variable in the query had no data. $data['project_file'] = strtolower( $file['name']['project_file'] ); removed the array from first part and variable worked.

关于mysql - Joomla 3.1 数据库更新查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19203700/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com