简体   繁体   中英

get value from combo box to php

this is my combo box page coding:

<?php
echo "<form method=post align=center>
<div id=myDiv>
<select name=userselect>
<option value=empty></option>
<option value=Confirm> Confirm </option>
<option value=Processing> Processing </option>
<option value=Pending> Pending </option>
<option value=Cancelled> Cancelled </option>
</select>
<button type=button name=combobox value=combobox onclick=loadXMLDoc()>Update</button>
</div>
</form>";
?>

this is my php code (another page):

<?php
if (isset($_POST['combobox']))
{
    $userselect = $_POST['userselect'];
    echo $userselect;
}
?>

if user select one value in combo box that value should store in db and then display what they are selected. for example if user select CONFIRM option that value stored in db after that it display CONFIRM instead of that combo box form and button. Here i can stored the combo box values in db successfully. thats not a problem and then here i used ajax method to show the msg instead of button place. Now, i want what user select it should display the same value. check these above coding and reply me ur suggestions...

Replace Your code with this:

<?php

//Connect To your Database File..

//After Connecting To Databse
$combo = mysqli_real_escape_string('yourconnectionlink', $_POST['userselect'])

echo "<form method='post' action='youractionfile.php' align='center'>
<div id='myDiv'>
<select name='userselect'>
<option value='empty'></option>
<option value='Confirm'> Confirm </option>
<option value='Processing'> Processing </option>
<option value='Pending'> Pending </option>
<option value='Cancelled'> Cancelled </option>
</select>
<input type='button' name='combobox' value='combobox'>Update</button>
</div>
</form>";

//Insert Data into Database File

if($_POST['userselect'])) {
   if(isset($_POST['userselect'])) {
     $query = "INSERT INTO tablename (your field names) VALUES ('".$combo."')";
     $res = mysqli_query('yourconnectionlink', $query);
     echo '1 row inserted';
   }
}
?>

finally i got it what i want. without using ajax method i can store the data to db and then combobox, button hide permanently if once we updated the status. this is my final coding...

 if ( $a_row['status'] != 'empty' ) {
        echo "\t<td>" . $a_row[$status] . "</td>\n";
    } 
    else {
        echo "\t<td><form action=statusdb.php method=post>
        <select name=update>
        <option value=empty></option>
        <option value=Confirm>Confirm</option>
        <option value=Processing>Processing</option>
        <option value=Pending>Pending</option>
        <option value=Cancelled>Cancelled</option></select>
        <input name=id type=hidden value='".$a_row['slno']."';>
        <input type=submit value=Update>
       </form>
        </td>\n";
    }

statusdb coding:

if (isset($_POST['id']))
{ 
$id = mysql_real_escape_string($_POST['id']);
$update= mysql_real_escape_string($_POST['update']);
$sql = mysql_query("UPDATE guest_details SET status = '$update' WHERE slno = '$id'");
if(!$sql)
{
    die("Error" .mysql_error());
}
}

i posted another question ( php combobox & button should hide once updated into mysql db and show success message instead of combobox & button place. ). i got help from that answer... so, only i posted the correct answer here..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM