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
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
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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.