2014-09-25 31 views
-2

這是我第一次使用PHP和MSSQL。我基本上想從PHP表單發送名稱,電子郵件到MSSQL數據庫,但是我在標題中出現錯誤。mssql_query():提供的參數不是有效的MS SQL-Link資源錯誤,不知道爲什麼

我的代碼遵循

的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 

    $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

什麼'GO'在做'( '$名稱', '$電子郵件')GO「;?'刪除它 – 2014-09-25 09:36:59

+0

在插件上的GO聲明,並告訴我們你正在得到的確切的錯誤 – gunas 2014-09-25 09:43:25

回答

0

出現此錯誤connection.php。從您的查詢中刪除Go

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

,並更改爲

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