Jump to content

error: unexpected '.' ...


glennn.php

Recommended Posts

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

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

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

$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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.