Hi all, this is my first post here and hope that someone could help me with my PHP/MySQL problem.
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:
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):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...
}
}
?>
Any hint on why the .$_GET['id_plants']. doesn't work?h_ttp://127.0.0.1:8181/tests/?id_plants=Bushes
Where's my mistake?
I'm stuck on this for 2 weeks and dunno how to fix my problem.
Really need help please
I remember I had the same problem a while back,
try doing this:
Grab the variable outside of the query... lmk if this works?Code:<?php
$id_plants = $_GET['id_plants'];
$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 />';
?>
Unfortunatelly it doesn't work
I think it's impossible!
It takes me to the homepage with the same example string as above![]()
Hehe nothing is impossiblewe will find it out, I am at work. I will post up when I get onto my laptop so I can actually try out the code..
Have you tried to connect it to the actual page rather than just the query?
instead do:Code:h_ttp://127.0.0.1:8181/tests/?id_plants=Bushes
Hrmmmm. Don't give upCode:h_ttp://127.0.0.1:8181/tests/plantpage.php?id_plants=Bushes
![]()
the big problem is that I'm working on a my own Wordpress plugin, and I think the main problem could be Wordpress.
You all could said to me, why don't you ask on the WP Forum?
Already done 4 times and no answers![]()
The only two things that I can see is.
1.) you do not need to establish a new database connection. Simply use the $wpdb global to get the results of your query.
and
2.) your form does not have an action either use PHP_SELF or # for the action.
Either one could cause your problem.
WORKING!!!!!!!! WORKING!!!!!!!! WORKING!!!!!!!! WORKING!!!!!!!! WORKING!!!!!!!!
The problem was not the $_GET but this:
I've added theCode:<form id="plants" action="<?php echo $action_url ?>" method="get">to my code and now everything works FINALLY!!Code:<?php echo $action_url ?>
The only problem is that the images doesn't work, but I could manage it.
I really thank you all of you, you helped me so much to think and fix the problem!
Really thank you!![]()
Glad you found the answer outSorry I wasn't much help, haha but trial and error!
![]()
You both helped me a lot, my focus was on the $_GET instead of the address.
Really thank you again!![]()
Seriously, I was concentrating on just that as well lol. So thank god you ended up getting it because that would have bugged till we did get it. lol![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks