我有一个 SELECT 框,其中的值是从数据库中填充的,下面是代码
<select name="ea_name" id="ea_name">
<option value="" selected="selected">Please Select...</option>
<?php
require 'include/DB_Open.php';
$sql = "SELECT ea_name FROM ea_error ORDER BY ea_name";
$myData = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($myData)){
echo "<option value=\"$ea_name\">" . $row['ea_name'] . "</option>";
}
include 'include/DB_Close.php';
?>
</select>
现在我有一个 jquery,这样当 SELECT 值更改时,它会从 db 中提取数据并将其填充到 textarea
$("#ea_name").on("change", function() {
$.ajax({
url: "retrieve.php",
type: "POST",
data: {
ea_name: $(this).val()
},
success: function(data) {
$("#results").html(data);
}
});
});
});
});
这是我现在的查询,
<?php
require 'include/DB_Open.php';
$ea_name = $_POST['ea_name'];
$sql="SELECT * FROM ea_error WHERE ea_name = '" . $ea_name . "'";
echo $sql;
$myData = mysql_query($sql) or die(mysql_error());
//to count if there are any results
$numrow = mysql_num_rows($myData) ;
if($numrow == 0)
{
echo "No results found.";
}
else
{
echo '<fieldset><legend><strong>Information</strong></legend>
<table width="619" border="0" align="center">
<tr><th scope="row">Error</th></tr>
<tr><th scope="row">Resolution</th></tr>
<tr><th scope="row">Contact/s</th></tr>';
while($info = mysql_fetch_array($myData))
{
echo "<form action='retrieve.php' method='post'>";
echo "<tr>";
echo "<td align='center'>" . "<textarea readonly=readonly name=error cols=75 rows=10> " . $info['error'] . "</textarea></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'>" . "<textarea readonly=readonly name=resolution cols=75 rows=10> " . $info['resolution'] . "</textarea></td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center'>" . "<textarea readonly=readonly name=contacts cols=75 rows=10> " . $info['contacts'] . "</textarea></td>";
echo "</tr>";
echo "</form>";
}
}
echo "</fieldset>";
include 'include/DB_Close.php';
?>
我已经添加echo $sql;
,所以我可以看到输出,这是我得到的:SELECT * FROM ea_error WHERE ea_name = ''未找到结果。
我试图查看源代码,我看到了这个:
注意:未定义的变量:C:\xampp\htdocs\XXX\view_transactions.php中第75行
开关中的 ea_name
第 75 行指的是这个echo "<option value=\"$ea_name\">" . $row['ea_name'] . "</option>";
我需要帮助来理解和修复这个错误……我是 php 编码的新手……谢谢