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'] . '"';
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.