我以前用过php,从来没有遇到过这个问题......
我有单选按钮,它们传递自己的价值。提交表单后,我已验证传递的值与我的代码中的 if 语句条件匹配。但是,它不会执行该路径。
For example, when the city radio button is selected, the if condition pertaining to city does not execute. 我通过在 if 语句之前放置一个 echo 语句进行了调试,它与 if 语句中的值匹配,因此我对它为什么不执行感到困惑。
如果有人可以提供帮助,我将不胜感激......我很困惑。
继承人的html:
<html>
<head>
<title>Lab 5</title>
<link rel='stylesheet' href='SearchForm.css' type='text/css' media='all' />
</head>
<body>
<p>You may use % as a wildcard character in your search.</p>
<form method='POST' action='index.php?type=search'>
<input type='text' name='search_param' value='' />
<input type='radio' name='search-type' value='City' id='city' />
<label for='city'>City</label>
<input type='radio' name='search-type' value='Country' id='country' />
<label for='country'>Country</label>
<input type='radio' name='search-type' value='Language' id='language' />
<label for='language'>Language</label>
<br /><br />
<input type='submit' name='submit' value='Search' />
</form>
<p>Or, <a href='index.php?type=insert'>perform an insertion.</a></p>
</body>
</html>
和PHP:
<?php
include 'connect.php';
$table = $_POST['search-type'];
$search = $_POST['search_param'];
if($table != NULL)
{
echo '<table>';
if($table == 'City')
{
$query = "SELECT * FROM city WHERE name ILIKE $1 ORDER BY name;";
$stmt = pg_prepare($connection, "city", $query);
$result = pg_execute($connection, "city", array($search));
while($row = pg_fetch_assoc($result))
{
cityTable($row);
}
echo '</table>';
}
}
else
{
echo 'Please select a table to query!';
}
正如你所看到的,我什至$search
从我的 if 条件中删除了变量,而不是直接进入帖子。
当我回应$search
它产生“城市”时......请帮忙!