无法使用PHP处理服务器请求
之前的问题被问到了,但没有答案,我遇到了这个错误,我希望得到一些帮助。我正在尝试连接到两个不同的服务器,从两个服务器检索数据,并使用价格将其显示在一个搜索按钮下 php是页面上的一个简单按钮,仅此而已 函数search_by_price.php是运行的SQL查询,用于从它所连接的2台服务器获取信息 我收到的错误是:第1列第2行的错误:文档末尾的额外内容 谢谢 引用的SQL语句:无法使用PHP处理服务器请求,php,Php,之前的问题被问到了,但没有答案,我遇到了这个错误,我希望得到一些帮助。我正在尝试连接到两个不同的服务器,从两个服务器检索数据,并使用价格将其显示在一个搜索按钮下 php是页面上的一个简单按钮,仅此而已 函数search_by_price.php是运行的SQL查询,用于从它所连接的2台服务器获取信息 我收到的错误是:第1列第2行的错误:文档末尾的额外内容 谢谢 引用的SQL语句: public XmlDocument SearchAccommodationByPrice(string Price
public XmlDocument SearchAccommodationByPrice(string Price)
{
string connectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
string query = "select " + allFields + " from Accommodations a, Users u, AccommodationImages i where"
+ " a.AccommodationPrice=@Price and u.userID = a.UserID and a.imgID = i.imgID";
SqlCommand sqlCommand = new SqlCommand(query);
sqlCommand.Parameters.AddWithValue("@Price", Price);
SqlDataAdapter sqlAdapter = new SqlDataAdapter();
sqlCommand.Connection = connection;
sqlAdapter.SelectCommand = sqlCommand;
DataSet dataSet = new DataSet("Accommodations");
sqlAdapter.Fill(dataSet, "Accommodations_List");
XmlDocument xmlDom = new XmlDocument();
xmlDom.LoadXml(dataSet.GetXml());
return xmlDom;
}
}
以下是我的index.php代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb">
<head>
<title>Property Search</title>
<meta name="ds364" content="ds364@greenwich.ac.uk" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/lumen/bootstrap.min.css" />
</head>
<body>
<div class="container">
<h1>Search Property Information</h1>
<div class="row">
<div class="col-md-6">
<h2>Property By Price</h2>
<form method="GET" action="search_by_price.php">
<input type="text" name="price" class="form-control" />
<button type="submit" class="btn btn-success" name="price">Search</button>
</form>
</div>
</div>
</div>
</body>
</html>'
财产搜索
搜寻物业资料
按价格计算的财产
搜寻
'
以下是我的php:
'<?php
header('Content-type: text/xml');
ini_set("soap.wsdl_cache_enabled",0);
if(isset($_REQUEST['price']))
{
$price = $_REQUEST['pprice'];
}
// This is to access .NET service
$args = array('price'=>$price);
$client = new SoapClient('http://stuiis.cms.gre.ac.uk/ds364/ServiceOrientedWeb/AccommodationSearch.asmx?WSDL');
$xmls = $client->SearchAccommodationByPrice($price)->SearchAccommodationByPriceResult->any;
$xmlDom1 = new DOMDocument();
$xmlDom1->loadXML($xmls);
//print_r($xmlDom1);
// This is to access Level 3 service (PHP Webservice)
$url = 'http://stuweb.cms.gre.ac.uk/~ds364/lvl3/search_by_price.php'.$price;
$xmlDom2 = new DOMDocument();
$xmlDom2->load($url);
//print_r($xmlDom2);
// This is to combine the services of PHP Webservice and .NET webservice
$xmlRoot1 = $xmlDom1->documentElement;
foreach ( $xmlDom2->documentElement->childNodes as $node2 ) {
$node1 = $xmlDom1->importNode($node2,true);
$xmlRoot1->appendChild($node1);
}
echo $xmlDom1->saveXML();
?>'
“$price);
$client=新的SoapClient('http://stuiis.cms.gre.ac.uk/ds364/ServiceOrientedWeb/AccommodationSearch.asmx?WSDL');
$xmls=$client->searchAgencationByPrice($price)->searchAgencationByPriceResult->any;
$xmlDom1=新的DOMDocument();
$xmlDom1->loadXML($xmls);
//打印(xmlDom1美元);
//这是为了访问3级服务(PHP Web服务)
$url='1http://stuweb.cms.gre.ac.uk/~ds364/lvl3/search_by_price.php.“$price;
$xmlDom2=新的DOMDocument();
$xmlDom2->load($url);
//打印(xmlDom2美元);
//这是为了结合PHP Webservice和.NET Webservice的服务
$xmlRoot1=$xmlDom1->documentElement;
foreach($xmlDom2->documentElement->childNodes作为$node2){
$node1=$xmlDom1->importNode($node2,true);
$xmlRoot1->appendChild($node1);
}
echo$xmlDom1->saveXML();
?>'
这是我的错误:
<br />
<b>Fatal error</b>: Uncaught SoapFault exception: [soap:Server] System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Data.SqlClient.SqlException: The parameterized query '(@Price nvarchar(4000))select a.AccommodationID,a.AccommodationN' expects the parameter '@Price', which was not supplied.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClien in <b>/home/ds364/public_nginx/search_by_price.php</b> on line <b>14</b><br />
致命错误:未捕获的SoapFault异常:[soap:Server]System.Web.Services.Protocols.SoapException:服务器无法处理请求。--System.Data.SqlClient.SqlException:参数化查询“(@Price nvarchar(4000))选择a.accountationId,a.accountationn”需要未提供的参数“@Price”。
位于System.Data.SqlClient.SqlConnection.OneError(SqlException异常,布尔断开连接,操作'1 wrapCloseInAction)
位于System.Data.SqlClient.SqlInternalConnection.OneError(SqlException异常,布尔断开连接,操作'1 wrapCloseInAction)
位于System.Data.SqlClient.TdsParser.ThroweException和Warning(TdsParserStateObject StateObjectStateObj、布尔调用方连接锁、布尔异步关闭)
位于System.Data.SqlClient.TdsParser.TryRun(RunBehavior RunBehavior、SqlCommand cmdHandler、SqlDataReader dataStream、BulkCopySimpleResultSet bulkCopyHandler、TdsParserStateObject stateObj、Boolean和dataReady)
位于System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()处
第14行的/home/ds364/public\u nginx/search\u by_price.php中的System.Data.SqlClien
一个可能的问题是打字错误:
if(isset($_REQUEST['price']))
{
$price = $_REQUEST['pprice'];
}
您编写了
pprice
,double p.您似乎遇到了很多问题:
1)在将任何输出发送到浏览器之前,需要声明PHP。这包括空格。
这是您向我们展示的注释代码 上述文件/行的状态是什么? 4)
正如你提到的,这里有一个基本的不一致性:
if(isset($_REQUEST['price']))
{
$price = $_REQUEST['pprice'];
}
在使用另一个值pprice
进行设置之前,为什么要询问是否设置了一个值price
。其中一个几乎肯定是打字错误。让我说清楚一点:
- 你为什么或你是否确定你打算这样做:
if(isset($_REQUEST['value1'])) { $price = $_REQUEST['value_2']; }
由于上面的问题4,
$price
的值未定义(null
)。没有人想阅读所有代码并搜索可能的问题。已编辑。希望对您有所帮助。这可能更多的是一个注释,而不是答案。这是我试图连接到的一台服务器上的变量名称,因此我认为这是正确的,因为它需要与接收服务器上的变量名称相匹配。@user1967788此处指出的问题不是实际名称,只是if块中的不匹配-您检查是否存在一个键price
,然后使用另一个键,该键可能不存在pprice
您的问题3与您确定的问题相同,我在问题中添加了SQL查询,并进行了您建议的其他更改,但是运气不好。@user1967788是这是我的php:
引用了search\u by\u price.php
文件?
if(isset($_REQUEST['price']))
{
$price = $_REQUEST['pprice'];
}
if(isset($_REQUEST['value1']))
{
$price = $_REQUEST['value_2'];
}
$xmls = $client->SearchAccommodationByPrice($price)->SearchAccommodationByPriceResult->any;