php – 提交搜索表单后未收到数据库的查询结果

我有两个文件,file.PHP amd get_xml.PHP.我可以,在两个PHP文件中没有问题echo表信息,但是当我想使用搜索表单查询数据时,将其发送到get_xml.PHP,我得不到任何结果.

Here is a working example along with all rows as a reference as to what is in the actual MySQL table.

在这代码本身:

file.PHP

<?PHP
$username="****";
$password="*******";
$database="******";

MysqL_connect(localhost,$username,$password);
@MysqL_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM markers";
$result=MysqL_query($query);

$num=MysqL_num_rows($result);

MysqL_close();
?>


<form action="get_xml2.PHP" method="post">
Name: <input type="text" name="name"><br>
Address: <input type="text" name="address"><br>
Type: <input type="text" name="type"><br>
<input type="Submit">
</form>

get_xml2.PHP

<?PHP
require("db_access.PHP");

function parsetoXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr); 
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','&quot;',$xmlStr); 
$xmlStr=str_replace("'",'&#39;',$xmlStr); 
$xmlStr=str_replace("&",'&amp;',$xmlStr); 
return $xmlStr; 
} 

$name=$_POST['name'];
$address=$_POST['address'];
$type=$_POST['type'];


// Opens a connection to a MysqL server
$connection=MysqL_connect (localhost, $username, $password);
if (!$connection) {
  die('Not connected : ' . MysqL_error());
}

// Set the active MysqL database
$db_selected = MysqL_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . MysqL_error());
}




// Select all the rows in the markers table
$query = sprintf(
   "SELECT name, address, type FROM markers WHERE name = '%s' AND address = '%s' AND     type = '%s'",
   MysqL_real_escape_string($name),
   MysqL_real_escape_string($address),
   MysqL_real_escape_string($type)
);
$result = MysqL_query($result);
if($result == false) {
   die(MysqL_error() . "<br />\n$query");
}
if(MysqL_num_rows($result) == 0) {
   user_error("No rows returned by:<br />\n$query");
} 

header("Content-type: text/xml");

// Start XML file, echo parent node
echo '<markers>';

// Iterate through the rows, printing XML nodes for each
while ($row = @MysqL_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'name="' . parsetoXML($row['name']) . '" ';
  echo 'address="' . parsetoXML($row['address']) . '" ';
  echo 'type="' . parsetoXML($row['type']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo '/>';
}

// End XML file
echo '</markers>';

?>

当你进行搜索时,你会看到你会得到这个:

> Query was empty
SELECT name, address, type 
FROM markers 
WHERE name = 'The Melting Pot' 
AND address = '14 Mercer St, Seattle, WA' 
AND type = 'restaurant'

但是,当我将xml中的代码更改为

$query = "SELECT * FROM markers WHERE 1";
$result = MysqL_query($query);
if (!$result) {
  die('Invalid query: ' . MysqL_error());
}

The xml happily retrieves ALL data in from the database, as seen here.

谢谢你的时间!

解决方法:

你可能会为此而踢自己.

$result = MysqL_query($result);

应该

$result = MysqL_query($query);

你不讨厌那个吗?

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...