我确定已经问过这个问题。我已经搜索了答案,但似乎找不到。我有这段代码可以从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);
我在做什么错了?
答案 0 :(得分:0)
我可以将数据和数据以及变量插入单元格中。
<?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));
}
}
?>