I want to run a different query based on the selection of a radio button

Hi
all

I want to execute a query based on the selection of a radio button

I have two radio buttons 1) own 2) attach

If user select own i want to run different query
If user select attach i want to run different query

Thanks

This should be what you need

PHP

if (isset($_POST['options'])){
    $sql = ($_POST['options'] == 'own') ? "SELECT * FROM table_name" : "SELECT * FROM table_name";

    if (!$result = mysql_query($sql)){
        die(mysql_error());
    }
}

HTML

<form action="" method="post">
    Own&nbsp;<input type="radio" name="options" value="own" />&nbsp;
    Attach&nbsp;<input type="radio" name="options" value="attach" />
    <br /><br />
    <input type="submit" value="Submit" />
</form>

thanks for ur response

But i want to fetch the records from mysql before submitting the form and populate one of the form field

Thanks in advance

You would need Ajax to do that, do you have any knowledge in javascript?

thanks for ur response

i have little bit knowledge in javascript

please give me the full code on this

Sitepoint have articles to help you with these kinds of things