Mailing List Archive



Back to the month index Back to the list index

Jean-Olivier Holingue (joh@shore.net)
Fri, 21 Nov 1997 14:11:35 -0500 (EST)


Date: Fri, 21 Nov 1997 14:11:35 -0500 (EST)
From: Jean-Olivier Holingue <joh@shore.net>
Subject: Re: bad type comparison?
Message-ID: <Pine.SUN.3.96.971121140543.28028B-100000@northshore.shore.net>

Jon, see my answers below.

Jean-Olivier

On Fri, 21 Nov 1997, Jon Wilson wrote:

> Greetings all,
>
> I've got a bit of a problem which I'm trying to solve exclusively with
> Lite/w3-msql. Here are the details:
>
> I've declared a table like so:
>
> if(msqlQuery($sock, "CREATE TABLE central_tab (
> census char(10),
> ...
> reas_code UINT)")<0)
>
> The "census" field will contains numeric values expressed as strings. I
> did this because there is the possibility that the user might accidentally
> type in a non-numeric value to query on in my HTML form:
>
> <FORM ACTION=/cgi-bin/w3-msql/query.html METHOD="POST">
> <INPUT NAME="census_num" TYPE=Text VALUE="census" SIZE="20" MAXLENGTH="8">
> <INPUT TYPE="submit" VALUE="Submit Query">
> <INPUT TYPE="reset" VALUE="Reset Form">
> </FORM>
>
> Ok, here is my problem: when I do a SELECT like this (in query.html):
>
> $qrystat = msqlQuery($sock,"SELECT central_tab.app_date
> FROM central_tab
> WHERE central_tab.census = '$census_num' ");
>
> where $census_num is '234567' (an ASCII string of numbers), w3-msql gives
> me the error: 'bad type for comparison'
>

This should work, because census is a char; if it does not, check your
code on query.html to be sure you correctly process the form and add teh
record in the database.

> I tried this:
>
> $char_census = (char) $census_num;
> $qrystat = msqlQuery($sock,"SELECT central_tab.app_date
> FROM central_tab
> WHERE central_tab.census = '$char_census' ");
>
> and still got the same thing. Hopefully this isn't a bug! As I am an mSQL
> newbie, can someone offer me a little insight? I am wanting to use the
> Lite language to get around this for the sake of easy portability, but if I
> have to, I can use something more powerful. Thanks...
>

$char_census = (char)$census_num would work if census_num was an int (but
according to your html it's not!)
Check also the extra space between (char) and $census_num.

HTH

Jean-Olivier Holingue
joh@shore.net