我在使用参数时遇到问题,我想从我网页上的文件上传中将上传的文件插入到MsSQL数据库中。我使用codeigniter作为我的框架。
控制器
function upload_gen048()
{
$data['filedate']=$this->input->post('fiil');
//print_r ($data);
$this->load->model('navi_model');
$query = $this->navi_model->upload_gen048($data);
模型 function upload_gen048($ data) {
$x = explode('.',$data['filedate']);
//print_r ($data);
$qString = "";
$qString .= '[dbo].[gen048upload] '; //STORED PROCEDURE
$qString .= "'" .$data['fiil']."','" .$data['filedate']."'";
echo $qString;
查看
<form id="upload" name="upload" action="<?php echo base_url(); ?>index.php/welcome/upload_gen048" method="POST" class="form-horizontal" enctype="multipart/form-data" onsubmit="return verify_upload()" >
<input style="border:1px solid" type="text" onfocus="true" name="fiil" id="fiil" value=""size="30" />
<input type="file" name="uploadData" id="uploadData" onChange="fileSelect();" style=""/>
这是我的存储过程,当我独立执行它时它全部工作但我无法从我的网页插入数据。
ALTER PROCEDURE [dbo].[gen048upload]
(
@fileDate VARCHAR(20)
)
AS BEGIN
SET NOCOUNT ON
declare @sql varchar(8000),@sourceTable varchar(500), @dynamic varchar(8000), @tablesuffix varchar(10)
select @tablesuffix=upper(substring(datename(m,convert(datetime,@fileDate)),1,3))+convert(varchar,year(convert(datetime,@fileDate)))
print @tablesuffix
create table #logs(
i int identity(1,1),
tableName varchar(50),
status varchar(30)
)
set @sourceTable ='gen_048_'+@tablesuffix
insert into #logs(tableName,status) select @sourceTable,'CREATED'
IF NOT EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = @sourceTable)
BEGIN
set @sql = '
CREATE TABLE '+@sourceTable+'
(
答案 0 :(得分:1)
function upload_gen048()
{
// Here you make a array, with a key 'filedate'
$data['filedate']=$this->input->post('fiil');
//print_r ($data);
$this->load->model('navi_model');
$query = $this->navi_model->upload_gen048($data);
function upload_gen048($data) {
$x = explode('.',$data['filedate']);
//print_r ($data);
$qString = "";
$qString .= '[dbo].[gen048upload] '; //STORED PROCEDURE
// Here you try to get array key 'fiil', but you haven't set that in your code.
$qString .= "'" .$data['fiil']."','" .$data['filedate']."'";
echo $qString;
删除$ data [&#39; fiil&#39;]并且您的代码应该有效。 var_dump($ data);要确切了解数组中的内容,您会看到$ data [&#39; fiil&#39;]不存在。