I need to get the option value of a select tag which is $r['usr_id']
when submitted to use that value in php query
here is my code :
<pre> <div class="form-group"> <label class="col-md-2 col-xs-12 control-label">Piloté Par</label> <div class="col-md-4 col-xs-12"> <?php // LOGIN TO DATABASE SCRIPT WRITTEN FOR MYSQLI $mysqli = new mysqli("localhost", "root", "", "schb"); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } // END OF LOGIN TO DB SCRIPT $query_ak = "SELECT id_usr, nom_usr, pnom_usr FROM user WHERE role='Pilote processus' AND id_usr NOT IN (SELECT pilot_id FROM processus)"; $result = $mysqli->query($query_ak); ?> <select class="form-control select" name="slctpilot" > <?php while ($r = mysqli_fetch_assoc($result)) { echo '<option value="' . $r['id_usr'] . '">' . $r['nom_usr'] . ' ' . $r['pnom_usr'] . '</option>'; } ?> </select> </div> </div> </pre>
Advertisement
Answer
When the form is submitted (posted) store it in a variable –
$userId = $_POST['slctpilot'];
If value="' . $r['id_usr'] . '"
-> value='23'
the $userId
will hold 23
.