Ankit Sharma
Ankit Sharma

Reputation: 4069

html select as input to mysql query

My previous problem got solved but know i want to use html select value as input to another mysql query. My code so far -

<?php
    $con=mysqli_connect("server","user","pwd","db");
    if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    $result = mysqli_query($con,"select eid from tbl1 order by eid;");
    ?>
    <select id="eid" size="1">                                      
    <option selected="true" disabled="disabled">Choose eid</option>        
<?
    while($row = mysqli_fetch_array($result))
    {
?>
    <option value="<? echo $row_list['eid']; ?>"<? if($row['eid']==$select){ echo "selected"; } ?>>
    <?echo $row['eid'];?>
    </option>

<?

    }
    ?>
    </select>
    <select name="tagging">
    <option selected="true" disabled="disabled">Choose tagging</option> 
    <option value="option1">option1</option>
    <option value="option2">option2</option>
    <option value="option3">option3</option>
    </select>
<?
    $result = mysqli_query($con,"select  distinct val from tbl2 where val!='' order by val;");
?>
    <select id='val'>
    <option selected="true" disabled="disabled">Choose val</option> 
<?

    while($row = mysqli_fetch_array($result))
    {
?>
    <option value="<? echo $row_list['val']; ?>"<? if($row['val']==$select){ echo "selected"; } ?>>
    <?echo $row['val'];?>
    </option>
<?

    }
    ?>
    </select>
<?  
    mysqli_close($con);
?> 

Now the output window have three html select, i want to pass this three value in mysql select query to show some result. But don't know how to do it. All kind of advice are welcome.

Upvotes: 0

Views: 2408

Answers (2)

Ravinder Reddy
Ravinder Reddy

Reputation: 24022

There are few things you need to include in your web script pages.

  1. All input fields should be enclosed in a <form object.
  2. All input fields that should go to server must have name="value" defined.
  3. Form must have action="url" defined, to submit to a different web page.
  4. Scripting language in the server, should read these name=value pairs and based on your condition, should pass to database engine to store in a table.

Upvotes: 1

Lord Zed
Lord Zed

Reputation: 790

Why dont you wrap those 3 <select></select> into a <form> tag and add action and method attributes such as <form action="file_to_handle_select_data.php" method="POST"> and than in file_to_handle_select_data.php run the queries from $_POST array.

Upvotes: 1

Related Questions