【问题标题】:mssql_query(): supplied argument is not a valid MS SQL-Link resource error, not sure whymssql_query(): 提供的参数不是有效的 MS SQL-Link 资源错误,不知道为什么
【发布时间】:2014-09-25 09:36:20
【问题描述】:

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

?>

【问题讨论】:

  • GO('$Name','$Email')GO"; 中做什么?删除它。
  • 删除插入语句中的GO。还要告诉我们您遇到的确切错误

标签: php sql sql-server


【解决方案1】:

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

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

并将其更改为

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-27
    • 1970-01-01
    • 1970-01-01
    • 2013-05-08
    相关资源
    最近更新 更多