Hi,
Just quote it :)
my $qname= $dbh->quote("$Name $Surnames[$idx]");
Then use as query:
SELECT username, dayofyear(startdate),
dayofyear(enddate),dayofyear(enddate) -
dayofyear(startdate)+1 , absencetype
FROM `absence`
where username = $qname
order by absencetype
Assuming $dbh is your database handle of course. I was tempted to use a
prepared query for this but I'm not sure if all databases handle prepared
select queries. Besides, quoting is probably more appropriate in this case.
Do note you no longer need (nor want) single quotes around $qname in the
query itself.
Greetings,
-----------------------------------
Frans Postma, (050-58) 81 852
ATOS Origin, Unix Support
"If at first you don't succeed, skydiving isn't for you"
> -----Oorspronkelijk bericht-----
> Van: Jattie van der Linde [mailto:[EMAIL PROTECTED]
> Verzonden: dinsdag 25 maart 2003 17:20
> Aan: [EMAIL PROTECTED]
> Onderwerp: select where clause question with replace subquestion
>
>
> I'm trying to build a dynamic piece of code that generates a
> HTML view like a year planner for all employees in the
> company all on one page. My appraoch is to use 2 Quesries,
> the first getting all the active employee names and the
> second then determines the dates of absence and plot that on
> a 365 dayscale to show the absence and type of absence on a
> simple sideways stacked barrgraph generated using shaded
> table fields. This works very well and my second query looks
> like this:
>
> SELECT username, dayofyear(startdate),
> dayofyear(enddate),dayofyear(enddate) -
> dayofyear(startdate)+1 , absencetype
> FROM `absence`
> where username = '$Name $Surnames[$idx]'
> order by absencetype
>
> The problem that I encounter is with the Irish surnames like
> O'Kelly and O'Flynn. In the where clause the variables will
> translate to:
>
> where username = 'Niall O'Kelly' and the Kelly part will
> cause an error message:
>
> DBD::mysqlPP::st execute failed: You have an error in your
> SQL syntax near 'Kelly'
>
> order by absencetype
> ' at
> line 3 at D:\Data\script\emp_year.cgi line 29.
>
> I was hoping to replace the ' with some escape code for '
> using a search and replace feature but I am not that familiar
> with search and replace yet. Can anyone offer me some
> valuable assistance or pointers to my problem.
>