I’ve used php before and never run into this problem….
I have radio buttons which pass on their own value. When my form is submitted I have verified that the value passed matches the if statement condition in my code. However, it will not execute that path.
For example, when the city radio button is selected, the if condition pertaining to city does not execute. I have debugged by placing an echo statement ahead of the if statement and it matches the value in the if statement, hence my confusion on why it does not execute.
If anyone can help I’d be grateful… I’m quite baffled.
Heres the 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>
and the 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!';
}
As you can see, I’ve even removed the variable $search from my if condition, instead going straight to the post.
When I’ve echoed $search it yields “city” so….. please help!
String comparisons in PHP are case sensitive, so instead of:
You should have:
Or: