INSERTing and ENUMs

INSERTing and ENUMs

am 09.02.2007 01:56:21 von wombat

I'm encountering the following problem:

I'm trying to create a new row by:

"INSERT INTO object_ix (name, address, phone, active) VALUES ('$a',
'$b', '$c', '$d')"

The "active" column is an ENUM to be set either YES or NO, however this
portion is failing to work. If I take out the "active" column, it works
just fine but I can't seem to be able to set an ENUM when creating the
row...

$d is set with a form using select with options YES and NO.

What am I doing wrong here?

Any help would be much appreciated. Thanks.

Re: INSERTing and ENUMs

am 09.02.2007 11:07:24 von Captain Paralytic

On 9 Feb, 00:56, wombat <6...@k.com> wrote:
> I'm encountering the following problem:
>
> I'm trying to create a new row by:
>
> "INSERT INTO object_ix (name, address, phone, active) VALUES ('$a',
> '$b', '$c', '$d')"
>
> The "active" column is an ENUM to be set either YES or NO, however this
> portion is failing to work. If I take out the "active" column, it works
> just fine but I can't seem to be able to set an ENUM when creating the
> row...
>
> $d is set with a form using select with options YES and NO.
>
> What am I doing wrong here?
>
> Any help would be much appreciated. Thanks.

"however this portion is failing to work"
How is it failing to work? Are you getting an error message? Are all
the fields apart from that one getting inserted? Is no row getting
inserted?
We need a bit more info here than "it doesn't work".

Try echoing the string so that you can see what the final query looks
like then paste it into phpmyadmin and see what that says about it.

Re: INSERTing and ENUMs

am 09.02.2007 16:04:57 von kenoli

On Feb 8, 4:56 pm, wombat <6...@k.com> wrote:
> I'm encountering the following problem:
>
> I'm trying to create a new row by:
>
> "INSERT INTO object_ix (name, address, phone, active) VALUES ('$a',
> '$b', '$c', '$d')"
>
> The "active" column is an ENUM to be set either YES or NO, however this
> portion is failing to work. If I take out the "active" column, it works
> just fine but I can't seem to be able to set an ENUM when creating the
> row...
>
> $d is set with a form using select with options YES and NO.
>
> What am I doing wrong here?
>
> Any help would be much appreciated. Thanks.

I'm using this same construct successfuly.

Make sure your table is set up correctly (I think mysql will force you
to do this, so it probably isn't your issue, but it may be useful to
check).

In the "type" column the choices need to have quotes like this:

'YES', 'NO' and in the default filed no quotes, like this:

NO

i found setting my variable for the unum field like this was helpful:

$d = escape_data($_POST['active']);
if ($d != "YES") {$d = 'NO';}

The "if" statement makes sure you have a valuei in that variable.

While you don't need it, escape_data() invokes the following function
which may help as well to get rid of any offending escapes or white
space:

function escape_data ($data) {
global $dbc;
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string(trim ($data), $dbc);
}

You need to be connected to a database to define and invoke it.

Hope this helps.

--Kenoli

Re: INSERTing and ENUMs

am 09.02.2007 17:07:05 von Mick White

wombat wrote:

> I'm encountering the following problem:
>
> I'm trying to create a new row by:
>
> "INSERT INTO object_ix (name, address, phone, active) VALUES ('$a',
> '$b', '$c', '$d')"

"INSERT INTO object_ix
(name, address, phone, active)
VALUES ($a, $b, $c, $d)"

I assume values are php variables.

Mick

>
> The "active" column is an ENUM to be set either YES or NO, however this
> portion is failing to work. If I take out the "active" column, it works
> just fine but I can't seem to be able to set an ENUM when creating the
> row...
>
> $d is set with a form using select with options YES and NO.
>
> What am I doing wrong here?
>
> Any help would be much appreciated. Thanks.

Re: INSERTing and ENUMs

am 09.02.2007 18:04:01 von wombat

In article <1171015644.786212.282790@k78g2000cwa.googlegroups.com>,
"Captain Paralytic" wrote:

> On 9 Feb, 00:56, wombat <6...@k.com> wrote:
> > I'm encountering the following problem:
> >
> > I'm trying to create a new row by:
> >
> > "INSERT INTO object_ix (name, address, phone, active) VALUES ('$a',
> > '$b', '$c', '$d')"
> >
> > The "active" column is an ENUM to be set either YES or NO, however this
> > portion is failing to work. If I take out the "active" column, it works
> > just fine but I can't seem to be able to set an ENUM when creating the
> > row...
> >
> > $d is set with a form using select with options YES and NO.
> >
> > What am I doing wrong here?
> >
> > Any help would be much appreciated. Thanks.
>
> "however this portion is failing to work"
> How is it failing to work? Are you getting an error message? Are all
> the fields apart from that one getting inserted? Is no row getting
> inserted?
> We need a bit more info here than "it doesn't work".
>
> Try echoing the string so that you can see what the final query looks
> like then paste it into phpmyadmin and see what that says about it.

Actually, the issue was a bug in the code I wrote elsewhere... at least
I now suspect. There was no obvious error in the page itself and it took
a few hours of picking through the code track track down the problem,
but that's now fixed. Bugs... gotta love'm.