mysql - PHP search form -
i new php please forgive if question or problem seem confusing trying create search form has 2 dropdown option: st. peter or jhs. user types in name of professor , choose school professor teach at. form has below
<form name=form action="form.php" method="get"> <input type="text" name="find" /> <select name="school[]" > <option value="">school</option> <option value="1">st.peter</option> <option value="2">jhs</option> </select> <input type="submit" name="submit" value="search" /> </form>
the form.php script using is
<?php $q=$_get["find"]; $s=$_get["school"]; $con = mysql_connect('localhost', 'peter', 'abc123'); if($q && ($s==st.peter)) echo "that professor belongs st.peter h.s"; else{echo "that professor not belong school"; } elseif($q && ($s==jhs)) echo "that professor belongs jhs h.s"; else{echo "that professor not belong school"; } ?>
when run this, output is. professor belongs st.peter h.s professor belongs jhs h.s
if change script see if first if statement correct eg.
<?php $q=$_get["find"]; $s=$_get["school"]; $con = mysql_connect('localhost', 'peter', 'abc123'); if($q && ($s==st.peter)) echo "that professor belongs st.peter h.s"; else{echo "that professor not belong school"; } ?>
this echos out professor belongs st.peter h.s, if change
if($q && ($s==st.peter))
to
if($q && ($s==st.p))
it echos out same thing. echos out professor belongs st.peter h.s,
that's because what's being sent "value" of option, not text. should looking "1" or "2"
if ($q && $s == 1)
Comments
Post a Comment