I am new to PHP so please forgive if this question or problem seem confusing
I am trying create a search form that has a 2 dropdown option: St. Peter or JHS. the user types in the name of a professor and then choose
the school the professor teach at. the form is 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 that i am using is
<?php
$q=$_GET["find"];
$s=$_GET["school"];
$con = mysql_connect('localhost', 'peter', 'abc123');
if($q && ($s==St.Peter))
echo "that professor belongs to St.peter H.S";
else{echo "that professor does not belong to this school"; }
elseif($q && ($s==JHS))
echo "that professor belongs to JHS H.S";
else{echo "that professor does not belong to this school"; }
?>
when i run this, the output i get is.
that professor belongs to St.peter H.S that professor belongs to JHS H.S
if i change the script just to see if the first if statement is correct eg.
<?php
$q=$_GET["find"];
$s=$_GET["school"];
$con = mysql_connect('localhost', 'peter', 'abc123');
if($q && ($s==St.Peter))
echo "that professor belongs to St.peter H.S";
else{echo "that professor does not belong to this school"; }
?>
this echos out that professor belongs to St.peter H.S, but if change
if($q && ($s==St.Peter))
to
if($q && ($s==St.P))
it echos out the same thing. this echos out that professor belongs to St.peter H.S,
That’s because what’s actually being sent is the “value” of the option, not the text. You should be looking for “1” or “2”