首页 > 解决方案 > PHP在SQL Server中插入文本值

问题描述

我想创建一个文本框,将输入的任何内容发送到我的数据库。但是,我不确定到目前为止我所做的事情将去哪里,因为我遇到了我的失败消息

查询 SQL Server 数据库时出错

任何帮助,将不胜感激。我目前也在使用 SQL Server 作为我的数据库。

  <?php

  $serverName = "serverName"; 
  $connectionInfo = array( "Database"=>"dbname", "UID"=>"username", "PWD"=>"password");
  $conn = sqlsrv_connect( $serverName, $connectionInfo);

  if( $conn ) {
       echo "Connection established.<br />";
  }else{
       echo "Connection could not be established.<br />";
       die( print_r( sqlsrv_errors(), true));
  }

  ?>
<!DOCTYPE html>
<html>
<body>

<p>Please type the car you are using:</p>

<form action="StartScreen.php" method="post">
  <input type = "text" id = "carType" name ="carName">
  <input type="submit" id= "submit" name="submit" value="Submit">

</form>
<?php
  $carType=($_POST['carName']);

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

$sql = "INSERT INTO carInfo(carType);
VALUES ($carType)";

$result = sqlsrv_query($conn,$sql)or die('Error querying MSSQL database');
}

?>

</body>
</html>

标签: phphtmlsql-server

解决方案


推荐阅读