Jump to content

Using radio buttons values in WHERE clause in query


LoneStarJack

Recommended Posts

Of course it's possible. You'll want to make sure the user hasn't designed their own form to submit a value you might not want them to.

 

You could use an array filled with the values you have in the radio buttons, and check against that.

 

<?php
$radioValues = array( 'option1', 'option2', 'option3' );
if( !in_array($_POST['radioButton'], $radioValues) ) {
   // user has entered a bad value
} else {
  $query = 'SELECT `columns` FROM `table` WHERE `column` = "' . $_POST['radioButton'] . '"';
}
?>

I forgot to mention that I do not want to reload the page or have two pages to do this.

 

If you want users to submit forms that don't refresh the page you'll need to use AJAX. Let's just concentrate getting your query working without AJAX first, since this is not the AJAX help forum.

You could use the query string to let the script know it's an AJAX call, but I really don't see the point. I find it nicer to separate the logic in to different files rather than have a single cluttered file that handles everything.

 

That doesn't mean my solution isn't valid, so I'm not sure what you meant by your second post.

 

Did you want coded examples? Because there's tons of these on the net already, just use google. If you want some help with your code, please post it so we can recommend changes or suggest more efficient ways to accomplish it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.