How do you take a string submitted by a form ( $_GET['name'] ) and check to see if it has a comma. If it does take the string and split it by the comma and search the database with the left side as the last name and the right side as the first name%.
If there is no comma then just search the database by the last name%.
Here is my code why would this not be working?
if ( eregi(",", $_GET['name']) ) {
// Split the string by the comma and remove whitespace
list( $first,$last ) = split(",", $_GET['name']);
$first = trim($first);
$last = trim($last);
// Query the database
$result = mysql_query("SELECT id_nbamdf,CONCAT(last_name,', ',name_mi) AS full_name,ssn FROM nbamdf WHERE last_name LIKE '$last' AND name_mi LIKE '$first%' ORDER BY last_name");
}
// If the string is just last name
else {
$result = mysql_query("SELECT id_nbamdf,CONCAT(last_name,', ',name_mi) AS full_name,ssn FROM nbamdf WHERE last_name LIKE '$_GET[name]%'");