glennn.php Posted April 5, 2008 Share Posted April 5, 2008 Parse error: syntax error, unexpected '.' in /home/content/g/l/e/glennnphp/html/HFPjobs/search1.php on line 74 $num_fields = count ($_POST['subspecialty']); for ($i = 0; $i < $num_fields; $i++){ if ($i < ($num_fields-1)) $where2 = $fields[$i] . " LIKE '%" . $string% . "' OR "; else $where = $fields[$i] . " LIKE '%" . $string% . "'"; } can anyone tell me what's wrong with this...? thanks G Link to comment https://forums.phpfreaks.com/topic/99677-error-unexpected/ Share on other sites More sharing options...
quiettech Posted April 5, 2008 Share Posted April 5, 2008 " LIKE '%" . $string% . "%' OR " and also on the else clause Link to comment https://forums.phpfreaks.com/topic/99677-error-unexpected/#findComment-509923 Share on other sites More sharing options...
coder_ Posted April 5, 2008 Share Posted April 5, 2008 <?php for ($i = 0; $i < $num_fields; $i++){ if ($i < ($num_fields-1)) $where2 = $fields[$i] . " LIKE '%" . $string . "%' OR "; else $where = $fields[$i] . " LIKE '%" . $string . "%'"; } ?> Link to comment https://forums.phpfreaks.com/topic/99677-error-unexpected/#findComment-509926 Share on other sites More sharing options...
glennn.php Posted April 5, 2008 Author Share Posted April 5, 2008 awesome - now this: $sql="SELECT * FROM $tbl_user WHERE specialty LIKE '%$where%' OR subspecialty LIKE '%$where2%' ORDER BY contact_name ASC"; is effin' that up... Link to comment https://forums.phpfreaks.com/topic/99677-error-unexpected/#findComment-509930 Share on other sites More sharing options...
quiettech Posted April 5, 2008 Share Posted April 5, 2008 '%$where%' you need to replace that with double quotes to have any hopes of the parser to interpret $where. Otherwise it will interpret $ literally. Link to comment https://forums.phpfreaks.com/topic/99677-error-unexpected/#findComment-509936 Share on other sites More sharing options...
kenrbnsn Posted April 5, 2008 Share Posted April 5, 2008 No, that's ok, since the entire string is enclosed in double quotes. To the OP, what is the error you're now receiving? Ken Link to comment https://forums.phpfreaks.com/topic/99677-error-unexpected/#findComment-509941 Share on other sites More sharing options...
glennn.php Posted April 5, 2008 Author Share Posted April 5, 2008 A fatal MySQL error occured. Query: Error: (1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%'' OR subspecialty LIKE '' ORDER BY contact_name ASC' at line 1 (? it's really line 87)... OK, here's the deal: $num_fields = count ($_POST['specialty']); for ($i = 0; $i < $num_fields; $i++){ if ($i < ($num_fields-1)) { $where = $fields[$i] . " LIKE '%" . $string . "%' OR "; } else { $where = $fields[$i] . " LIKE '%" . $string . "%'"; } } $num_fields = count ($_POST['subspecialty']); for ($i = 0; $i < $num_fields; $i++){ if ($i < ($num_fields-1)) { $where2 = $fields[$i] . " LIKE '%" . $string . "%' OR "; } else { $where2 = $fields[$i] . " LIKE '%" . $string . "%'"; } } $sql="SELECT * FROM $tbl_user WHERE specialty LIKE \"$where\" OR subspecialty LIKE \"$where2\" ORDER BY contact_name ASC"; causes no errors, but neither returns any results I'm trying to search 2 groups of selected checkboxes against records/fields containing an array of the same checkboxes. field 'specialty' would contain Neuropathology, Cardiovascular Pathology, Clinical (CP), Chemical Pathology, etc... any help? Thanks Link to comment https://forums.phpfreaks.com/topic/99677-error-unexpected/#findComment-509943 Share on other sites More sharing options...
kenrbnsn Posted April 5, 2008 Share Posted April 5, 2008 Strings in MySQL are delimited by single quotes, not double quotes. Change <?php $sql="SELECT * FROM $tbl_user WHERE specialty LIKE \"$where\" OR subspecialty LIKE \"$where2\" ORDER BY contact_name ASC"; ?> to <?php $sql="SELECT * FROM $tbl_user WHERE specialty LIKE '$where' OR subspecialty LIKE '$where2' ORDER BY contact_name ASC"; ?> Note: I just re-read your code -- you're putting in the "LIKE" clause into the $where & $where2 variables, so your query is reading "LIKE LIKE" which is wrong. Try <?php $sql="SELECT * FROM $tbl_user WHERE specialty $where OR subspecialty $where2 ORDER BY contact_name ASC"; $rs = mysql_query($sql) or die("Problem with the query: $sql<br>" . mysql_error()); ?> Ken Link to comment https://forums.phpfreaks.com/topic/99677-error-unexpected/#findComment-509946 Share on other sites More sharing options...
glennn.php Posted April 5, 2008 Author Share Posted April 5, 2008 $sql="SELECT * FROM $tbl_user WHERE specialty LIKE '$where' OR subspecialty LIKE '$where2' ORDER BY contact_name ASC"; causes Error: (1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%'' OR subspecialty LIKE ' LIKE '%%'' ORDER BY contact_name ASC' at line 1 Link to comment https://forums.phpfreaks.com/topic/99677-error-unexpected/#findComment-509947 Share on other sites More sharing options...
AndyB Posted April 5, 2008 Share Posted April 5, 2008 apparently $where and $where2 have no values. Show us the code that obtains them. Link to comment https://forums.phpfreaks.com/topic/99677-error-unexpected/#findComment-509949 Share on other sites More sharing options...
glennn.php Posted April 5, 2008 Author Share Posted April 5, 2008 right: $num_fields = count ($_POST['specialty']); for ($i = 0; $i < $num_fields; $i++){ if ($i < ($num_fields-1)) { $where = $fields[$i] . " LIKE '%" . $string . "%' OR "; } else { $where = $fields[$i] . " LIKE '%" . $string . "%'"; } } echo $where; $num_fields = count ($_POST['subspecialty']); for ($i = 0; $i < $num_fields; $i++){ if ($i < ($num_fields-1)) { $where2 = $fields[$i] . " LIKE '%" . $string . "%' OR "; } else { $where2 = $fields[$i] . " LIKE '%" . $string . "%'"; } } echo $where2; echoes " LIKE '%%' " even though i've posted checkbox values <LI><INPUT type="checkbox" name="specialty[]" value="Anatomic (AP)">Anatomic (AP) <LI><INPUT type="checkbox" name="specialty[]" value="Anatomic & Clinical(AP/CP)">Anatomic & Clinical(AP/CP) (incidentally, these values post TO the database using via $checkbox1 = $_POST['specialty']; if ($checkbox1 != '') { $string1 = implode($checkbox1,", "); } else { $string1 = ''; } $checkbox2 = $_POST['subspecialty']; if ($checkbox2 != '') { $string2 = implode($checkbox2,", "); } else { $string2 = ''; } //Create a confirmation code //$rand_str = random_string($max = 20); //Place the user into the database. $sql="INSERT INTO... apparently $where and $where2 have no values. Show us the code that obtains them. Link to comment https://forums.phpfreaks.com/topic/99677-error-unexpected/#findComment-509952 Share on other sites More sharing options...
glennn.php Posted April 5, 2008 Author Share Posted April 5, 2008 this was working somewhat: $checkbox1 = $_POST['specialty']; if ($checkbox1 = '') { $string1 = explode($checkbox1,", "); } else { $string1 = ''; } $checkbox2 = $_POST['subspecialty']; if ($checkbox2 = '') { $string2 = explode($checkbox2,", "); } else { $string2 = ''; } $sql="SELECT * FROM $tbl_user WHERE specialty '$string1' OR subspecialty '$string2' ORDER BY contact_name ASC"; using implode or explode, but not getting accurate results... HELP? ??? Link to comment https://forums.phpfreaks.com/topic/99677-error-unexpected/#findComment-509954 Share on other sites More sharing options...
glennn.php Posted April 5, 2008 Author Share Posted April 5, 2008 yeah, i was noticing the 2 LIKES also - this worked, but returned ALL records instead of those that i had selected... it's still not parsing my checkbox selections... Strings in MySQL are delimited by single quotes, not double quotes. Change <?php $sql="SELECT * FROM $tbl_user WHERE specialty LIKE \"$where\" OR subspecialty LIKE \"$where2\" ORDER BY contact_name ASC"; ?> to <?php $sql="SELECT * FROM $tbl_user WHERE specialty LIKE '$where' OR subspecialty LIKE '$where2' ORDER BY contact_name ASC"; ?> Note: I just re-read your code -- you're putting in the "LIKE" clause into the $where & $where2 variables, so your query is reading "LIKE LIKE" which is wrong. Try <?php $sql="SELECT * FROM $tbl_user WHERE specialty $where OR subspecialty $where2 ORDER BY contact_name ASC"; $rs = mysql_query($sql) or die("Problem with the query: $sql<br>" . mysql_error()); ?> Ken Link to comment https://forums.phpfreaks.com/topic/99677-error-unexpected/#findComment-509956 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.