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

时间:2014-09-25 09:36:21

标签: php sql sql-server

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

?>

1 个答案:

答案 0 :(得分:0)

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

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

并将其更改为

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