mysql - Save dropdown list value to php session -
i have created drop down list populated data mysql db, im trying save selected value in session variable im not sure how write (where *** are)? , need posted server side eve though in php?
<?php $servername1 = "localhost"; $username1 = "root"; $password1 = ""; $dbname1 = "gpdb1"; $conn1 = new mysqli($servername1, $username1, $password1, $dbname1); if ($conn1->connect_error) { die("connection failed: " . $conn1->connect_error); } $sql2 = "select doctorid, title, surname doctors"; $result2 = $conn1->query($sql2); echo "<select name='doctor' value=''><option>select doctor</option>"; if ($result2->num_rows > 0) { foreach($result2 $row2) {echo "<option value=".$row2['doctorid'].">".$row2['title']." ".$row2['surname']."</option>"; } }echo "</select>"; $_session['selected']=***; if (isset($_session['selected'])){ echo $session['selected'];} ?>
thanks :)
first, advise indent code, better readability !
the html attribute "value" in tag isn't useful, can remove it.
and then, not useful control session field isset() since you're setting above.
i think need control if given value in post field correct.
the line looking :
$_session['selected'] = $_post['doctor'];
Comments
Post a Comment