mssql_query():提供的参数不是有效的MS SQL链接资源错误,不确定原因


mssql_query(): supplied argument is not a valid MS SQL-Link resource error, not sure why

这是我第一次使用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>

和连接.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);
?>

发生此错误是因为您的查询未能执行。从查询中删除Go

 $query = "INSERT INTO dbo.customers (customerName,customerEmail) VALUES
('$Name','$Email')GO";
                   ^

并将其更改为

 $query = "INSERT INTO dbo.customers (customerName,customerEmail) VALUES 
('$Name','$Email')";