Forum Moderators: coopster

Message Too Old, No Replies

cannot get query string to work

         

section9

2:50 pm on Mar 8, 2006 (gmt 0)



The following code is a sample php page that is sending variables that it has recieved from flash to a MYSQL database. Flash is sending ok,so no problems there. I have a syntax error or maybe i have built the query wrong all together. can anyone help resolve the problem. The debugger is pointing to this line in the code;

$unique = ' AND ethnic_origin LIKE 'cau%'';

giving the dreaded Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING

Basically it is a database containing details of peoples talents and physical attributes. Ethnic Origin the part of the programme that is coming up with the error contains either black, oriental, asian or european/caucasian as an entry in the field for a persons ethnic origin. So for 'NOT LIKE caucasian/european' i am trying to get the database to return all people who are not that that ethnicity, ie black, asian, oriental. Help?

<?php
//this is a sample of the variables posted from flash //that a user wants to search for.
$_POST['sex']='male';
$_POST['eye_colour']='all';
$_POST['ethnic_origin']='all';
$_POST['hair_colour']='all';
$_POST['age_start']='1987-01-01';
$_POST['age_finish']='2006-01-01';
$_POST['talent']='none';

// include the Database classes
require_once('database_mysql.php5');
// escape quotes and apostrophes if magic_quotes_gpc off
if (!get_magic_quotes_gpc()) {
foreach($_POST as $key=>$value) {
$temp = addslashes($value);
$_POST[$key] = $temp;
}
}

$sql = 'select * from kidzdata';

if ($_POST['sex']!= 'all') {
$unique = ' WHERE sex = "'.$_POST['sex'].'"';

}elseif($_POST['sex'] == 'all') {

$unique = ' where sex LIKE '%'';
}

$sql .= $unique;

if ($_POST['eye_colour']!= 'all') {
$unique = ' AND eye_colour = "'.$_POST['eye_colour'].'"';

}elseif($_POST['eye_colour'] == 'all') {

$unique = ' AND eye_colour LIKE '%'';
}

$sql .= $unique;

if ($_POST['hair_colour']!= 'all') {
$unique = ' AND hair_colour = "'.$_POST['hair_colour'].'"';

}elseif($_POST['hair_colour'] == 'all') {

$unique = ' AND hair_colour LIKE '%'';
}

$sql .= $unique;

if ($_POST['ethnic_origin']!= 'caucasian/european') {
$unique = ' AND ethnic_origin NOT LIKE "caucasian/european'';

}elseif($_POST['ethnic_origin'] == 'caucasian/european') {
$unique = ' AND ethnic_origin LIKE 'cau%'';

}elseif($_POST['ethnic_origin'] == 'all') {
$unique = ' AND ethnic_origin LIKE '%'';
}

$sql .= $unique;

if ($_POST['talent']!= 'none') {

$unique = ' AND ( talenta = "'.$_POST['talent'].'" OR talentb = "'.$_POST['talent'].'"
OR talentc = "'.$_POST['talent'].'" OR talentd = "'.$_POST['talent'].'"
OR talente = "'.$_POST['talent'].'" OR talentf = "'.$_POST['talent'].'"
OR talentg = "'.$_POST['talent'].'" OR talenth = "'.$_POST['talent'].'"
OR talenti = "'.$_POST['talent'].'" OR talentj = "'.$_POST['talent'].'"
OR talentk = "'.$_POST['talent'].'" OR talentl = "'.$_POST['talent'].'"
OR talentm = "'.$_POST['talent'].'" OR talentn = "'.$_POST['talent'].'"
OR talento = "'.$_POST['talent'].'")';

}

$sql .= $unique;

echo getDetails($sql);

function getDetails($sql) {

$db = new Database('db79.oneandone.co.uk','dbo132084134','spectre','db132084134');
$result = $db->query($sql);
$numrows =$result->num_rows;
if ($numrows <1) {
$errormessage = 'There is no match for your search at this point in time';
echo 'database return=n&message='.urlencode($errormessage);
}

$details ="total=$numrows";
$counter = 0;

while ($row = $result->fetch_assoc()) {
$details .= '&first_name'.$counter.'='.($row['first_name']);
$details .= '&family_name'.$counter.'='.($row['family_name']);
$details .= '&dob'.$counter.'='.urlencode($row['dob']);
$details .= '&age'.$counter.'='.urlencode($row['age']);
$details .= '&hair_colour'.$counter.'='.urlencode($row['hair_colour']);
$details .= '&eye_colour'.$counter.'='.urlencode($row['eye_colour']);
$details .= '&ethnic_origin'.$counter.'='.urlencode($row['ethnic_origin']);
$details .= '&i_want_to_be'.$counter.'='.urlencode($row['i_want_to_be']);
$details .= '&favourite_food'.$counter.'='.urlencode($row['favourite_food']);
$details .= '&talenta'.$counter.'='.urlencode($row['talenta']);
$details .= '&talentb'.$counter.'='.urlencode($row['talentb']);
$details .= '&talentc'.$counter.'='.urlencode($row['talentc']);
$details .= '&talentd'.$counter.'='.urlencode($row['talentd']);
$details .= '&talente'.$counter.'='.urlencode($row['talente']);
$details .= '&talentf'.$counter.'='.urlencode($row['talentf']);
$details .= '&talentg'.$counter.'='.urlencode($row['talentg']);
$details .= '&talenth'.$counter.'='.urlencode($row['talenth']);
$details .= '&talenti'.$counter.'='.urlencode($row['talenti']);
$details .= '&talentj'.$counter.'='.urlencode($row['talentj']);
$details .= '&talentk'.$counter.'='.urlencode($row['talentk']);
$details .= '&talentl'.$counter.'='.urlencode($row['talentl']);
$details .= '&talentm'.$counter.'='.urlencode($row['talentm']);
$details .= '&talentn'.$counter.'='.urlencode($row['talentn']);
$details .= '&talento'.$counter.'='.urlencode($row['talento']);

$counter++;
}


echo $details;
$db->close();
}


?>

jatar_k

5:31 pm on Mar 8, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld section9,

the line
$unique = ' AND ethnic_origin LIKE 'cau%'';

has mismatched quotes. You could use double quotes around the string or you could escape the single quotes inside. I would go with double quotes outside, like so

$unique = " AND ethnic_origin LIKE 'cau%'";

jatar_k

10:39 pm on Mar 8, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you may also be experiencing errors above the lines it says

like this one

$unique = ' AND hair_colour LIKE '%'';

should be

$unique = " AND hair_colour LIKE '%'";

the mismatched quotes cause the errors to be reported farther down in the code