savagenoob Posted June 21, 2010 Share Posted June 21, 2010 Why am I getting an error on this elseif statement? I know its something simple.... $agency=$_SESSION['SESS_AGENCY']; $search=$_POST["keyword"]; $field=$_POST["field"]; if($field == "PolNum"){ echo "<table>"; $query = "SELECT auto.ClientID, home.ClientID, auto.PolNum, home.PolNum FROM auto, home WHERE auto.'$field' OR home.'$field' LIKE '%$search%' AND Agency = '$agency'"; $result = mysql_query($query)or die(mysql_error()); $numrows = mysql_num_rows($result); if($numrows == 0){ echo "No results returned for " . $search; } while($myrow = mysql_fetch_assoc($result)) { $clientid = $myrow['ClientID']; $clientdata = mysql_query("SELECT * FROM clients WHERE ID ='$clientid'")or die(mysql_error()); $client = mysql_fetch_assoc($clientdata); echo "<tr><td><a href=\"client.php?ID=$clientid\">" . $client['First_Name'] . " " . $client['Last_Name'] . " " . $myrow['PolNum'] . "</a></td></tr>\"" ; } elseif($field == "Last_Name") { ?> <table> <?php $query = "SELECT * FROM clients WHERE $field LIKE '%$search%' AND Agency = '$agency'"; $result = mysql_query($query)or die(mysql_error()); while($myrow = mysql_fetch_assoc($result)) {//begin of loop echo "<tr><td><a href=\"client.php?ID=\"" . $myrow['ID'] . "\">" . $myrow['First_Name'] . " " . $myrow['Last_Name'] . "</a></td></tr> "; } } ?> Quote Link to comment Share on other sites More sharing options...
inversesoft123 Posted June 21, 2010 Share Posted June 21, 2010 Why are you using "else if" ? <?php $agency=$_SESSION['SESS_AGENCY']; $search=$_POST["keyword"]; $field=$_POST["field"]; if($field == "PolNum"){ echo "<table>"; $query = "SELECT auto.ClientID, home.ClientID, auto.PolNum, home.PolNum FROM auto, home WHERE auto.'$field' OR home.'$field' LIKE '%$search%' AND Agency = '$agency'"; $result = mysql_query($query)or die(mysql_error()); $numrows = mysql_num_rows($result); if($numrows == 0){ echo "No results returned for " . $search; } while($myrow = mysql_fetch_assoc($result)) { $clientid = $myrow['ClientID']; $clientdata = mysql_query("SELECT * FROM clients WHERE ID ='$clientid'")or die(mysql_error()); $client = mysql_fetch_assoc($clientdata); echo "<tr><td><a href=\"client.php?ID=$clientid\">" . $client['First_Name'] . " " . $client['Last_Name'] . " " . $myrow['PolNum'] . "</a></td></tr>\"" ; } if($field == "Last_Name") { ?> <table> <?php $query = "SELECT * FROM clients WHERE $field LIKE '%$search%' AND Agency = '$agency'"; $result = mysql_query($query)or die(mysql_error()); while($myrow = mysql_fetch_assoc($result)) {//begin of loop echo "<tr><td><a href=\"client.php?ID=\"" . $myrow['ID'] . "\">" . $myrow['First_Name'] . " " . $myrow['Last_Name'] . "</a></td></tr> "; } } } ?> Quote Link to comment Share on other sites More sharing options...
phpchamps Posted June 21, 2010 Share Posted June 21, 2010 put a } before else if. it should be }elseif($field == "Last_Name"){ Quote Link to comment Share on other sites More sharing options...
shortysbest Posted June 21, 2010 Share Posted June 21, 2010 Shouldn't it be else if rather than elseif Quote Link to comment Share on other sites More sharing options...
chaiwei Posted June 21, 2010 Share Posted June 21, 2010 ya.. phpchamps is correct. you are missing 1 } }elseif($field == "Last_Name"){ Quote Link to comment Share on other sites More sharing options...
savagenoob Posted June 21, 2010 Author Share Posted June 21, 2010 Thanks guys Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.