繁体   English   中英

将PHP 7变量插入SQL Server

[英]Inserting PHP 7 variables into SQL Server

我相信这个问题已经被问到了。 我已经搜索了答案,但似乎找不到。 我有这段代码可以从PHP将INSERT数据连接到MS Sql数据库中。 它不起作用。

 <!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<?php
//Session Start
session_start();
include '/includes/dbconn.mssql.php';

ini_set('display_errors','On');
?>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <div>

    </div>
</body>
<?php        

        $sql = "INSERT INTO 
agents(fname,lname,date,dl1,ul1,lat1,jit1,dl2,ul2,lat2,jit2,dl3,ul3,lat3,jit3,UCN,ISP,IP,mmake,mmodel,[user],pass,email,winver,modem,mon1mk,mon1mdl,mon2mk,mon2mdl,headset,hmake,hmodel,webcam,prospect,[current],planul,plandl,station) "
                    . "VALUES('Janice','Smith','2/15/2019','10','10','1','1','10','10','1','1','10','10','1','1','333689','Xfinity','10.0.0.1','Ubee','100','admin','password','jane.smith@companyinc.com','null','null','Acer','100','AOC','5','1','Plantronic','54','1','0','1','150','50','28')";
            //      $sql = "INSERT INTO agents(fname,lname,date,dl1,ul1,lat1,jit1,dl2,ul2,lat2,jit2,dl3,ul3,lat3,jit3,UCN,ISP,IP,mmake,mmodel,user,pass,email,winver,modem,mon1mk,mon1mdl,mon2mk,mon2mdl,workspace,monitor1,monitor2,headset,hmake,hmodel,webcam,prospect,current,planul,plandl,station) VALUES('$fname','$lname','$date','$dl1','$ul1','$lat1','$jit1','$dl2','$ul2','$lat2','$jit2','$dl3','$ul3','$lat3','$jit3','$UCN','$ISP','$IP','$mmake','$mmodel','$user','$pass','$email','$winver','$modem','$mon1mk','$mon1mdl','$mon2mk','$mon2mdl','$workspace','$monitor1','$monitor2','$headset','$hmake','$hmodel','$webcam','$prospect','$current','$planul','$plandl','$station')";
            $result = sqlsrv_query($conn,$sql);
            $echo = sqlsrv_rows_affected;
            if(!$result) {
    echo 'Your code failed. $echo';
}
else {
    echo 'Success! $echo'; 
}
?>
</html>

当我在Edge中运行代码时,它说

致命错误:在第34行中调用未定义的函数sqlsrv_query()

第34行正在

$result = sqlsrv_query($conn,$sql);

我究竟做错了什么?

我将其插入到具有数据和变量的单元格中的数据。

     <?php

   $uploadDir = 'pics/';

   if(isset($_POST['upload'])){ 

       $fileName = $_FILES['monitor1']['name'];
       $tmpName  = $_FILES['monitor1']['tmp_name'];
       $fileSize = $_FILES['monitor1']['size'];
       $fileType = $_FILES['monitor1']['type'];

       $filePath = $uploadDir . $fileName;

       $result = move_uploaded_file($tmpName, $filePath);

       if (!$result) {
           echo "Error uploading <strong>file</strong>";
           exit;
}


       $sql =  "INSERT INTO agents(fname,lname,employee_status,dl1,ul1,lat1,jit1,monitor1) "
               . "  VALUES('".$_POST['fname']."',
                        '" .$_POST['lname']."',
                        '" .$_POST['status']."',
                        '" .$_POST['dl1']."',
                        '" .$_POST['ul1']."',
                        '" .$_POST['lat1']."',
                        '" .$_POST['jit1']."',
                        '" .$_FILES['monitor1']."')";                            

              $result = sqlsrv_query($conn,$sql);

              if( $result === false ) {
 die( print_r( sqlsrv_errors(), true));
}

   }

?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM