I need to create a form that could grad on the fly some variables like name, surname, a checkbox and list choices and use one of them as a search string in the MySQL database table.
I've written some code:
<?
function display()
{
global $wpdb;
$wpdbtest = new wpdb('DB_USERNAME', 'DB_PASSWORD', 'DB_NAME', 'localhost');
$wpdbtest->show_errors();
?>
<form method="get">
Kind of plants:<br />
<select name="id_plants">
<option value=""></option>
<option value="tree">Trees</option>
<option value="shrub">Shrubs</option>
<option value="bush">Bushes</option></select>
<br />
<input type="submit" value="View">
</form>
<?php
$myplants = $wpdbtest->get_results("SELECT *
FROM plants_table
WHERE id_plants = '".$_GET['id_plants']."'");
foreach ($myplants as $myplant) {
echo $myplant->id_category, '<br />';
echo $myplant->id_name, '<br />';
// escape from PHP ... ?>
<img src="../plants/wp-content/plugins/plants_plugin/plants_images/uploads/<? echo $myplant->id_image; ?>" width="250px" height="356px"">
<br /><br />
<? // starting up PHP again...
}
}
?>
The problem is that when I press the "View" button instead to stay in the same page and have the category, name and image display, it goes to the homepage with this URL (eg.: in this case the URL is display for the Bushes selection):
Quote
h_ttp://127.0.0.1:8181/tests/?id_plants=Bushes
Any hint on why the .$_GET['id_plants']. doesn't work?
Where's my mistake?
I'm stuck on this for 2 weeks and dunno how to fix my problem.
Really need help please


Sign In
Create Account


Back to top









