php - 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>
解决方案
推荐阅读
- node.js - 为 Node.js 模块中重新导出的 JS 函数生成 TypeScript 声明
- android - Android (Kotlin) 中的 lateinit 问题 - java.lang.RuntimeException
- android - 无法解析 Android Studio 中的符号“注释”?
- angular - 显示相同的时间计数,但同时显示两个组件
- c++ - 使用 sfml 在矩形的向量中查找鼠标点击
- javascript - 如何调用同名的父函数?
- swift - 模态控制器在关闭时仍然是最顶层的视图控制器
- c# - 从所有 XML 值中修剪空格
- r - ggplot:将两个变量绘制成一个方面
- node.js - 如何使用 localhost 连接 docker 容器?