这是我第一次使用PHP和MSSQL。我基本上想要从PHP表单发送名称,电子邮件到MSSQL数据库,但我收到标题错误。
我的代码如下
的index.php
<title></title>
</head>
<body>
<form action="connection.php" name="frmAdd" method="post">
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">Name</div></th>
<th width="160"> <div align="center">Email</div></th>
</tr>
<tr>
<td><input type="text" name="Name" size="20"></td>
<td><input type="text" name="Email" size="20"></td>
</tr>
</table>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
和connection.php
<?php
$Name = $_POST['Name'];
$Email= $_POST['Email'];
$dbc = mssql_connect('localhost','**','**.','**')or die('Error connecting to the SQL Server database.');
$query = "INSERT INTO dbo.customers (customerName,customerEmail) VALUES ('$Name','$Email')GO";
$result = mssql_query($dbc,$query)or die('Error querying MSSQL database');
mssql_close($dbc);
?>
答案 0 :(得分:0)
发生此错误是因为您的查询无法执行。从查询中删除Go
。
$query = "INSERT INTO dbo.customers (customerName,customerEmail) VALUES
('$Name','$Email')GO";
^
并将其更改为
$query = "INSERT INTO dbo.customers (customerName,customerEmail) VALUES
('$Name','$Email')";