duandu9260 2016-01-18 01:55
浏览 33

使用codeigniter将数据上传到MsSQL中使用适当的参数

I am having a trouble using a parameters, I want to insert the uploaded file into the MsSQL database from the file upload in my webpage. I am using codeigniter as my framework.

Controller

function upload_gen048()
{

$data['filedate']=$this->input->post('fiil');
//print_r ($data);

$this->load->model('navi_model');
$query = $this->navi_model->upload_gen048($data);

Model function upload_gen048($data) {

$x = explode('.',$data['filedate']);

//print_r ($data);

$qString = "";
$qString .= '[dbo].[gen048upload] '; //STORED PROCEDURE
$qString .= "'" .$data['fiil']."','" .$data['filedate']."'";
echo $qString;

View

<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=""/>

here is my Stored Procedure, it is all working when I execute it independently but I cant insert data from my webpage.

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+'
    (
  • 写回答

1条回答 默认 最新

  • dongling4383 2016-01-18 14:00
    关注
    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;
    

    Remove $data['fiil'] and your code should work. Also var_dump($data); to see exactly what is in your array, you would have seen that $data['fiil'] does not exist.

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘