You need to have quotes around test in the insert statement. So it would
be as follows:

sprintf (query, "INSERT INTO tablename (userid) VALUES(\"%s\")", test");
res=mysql_query(connection, query);

Oviously query needs declaration here, but the SQL has to be quoted
exactly the same as if you were doing it from the command line.

Hope this helps,
Sean

On Mon, 26 Mar 2001, Rick Emery wrote:

> Maybe you just gave a snippet, but I don't see where you established the
> connection to the database, thereby giving the variable "connection" a
> value.  It appears to be undefined.  Therefore, the mysql_query() would
> fail.
> 
> -----Original Message-----
> From: john lin [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, March 25, 2001 2:56 PM
> To: [EMAIL PROTECTED]
> Subject: inserting into mysql database in linux using C
> 
> 
> I am a senior in Polytechnic University working on my
> senior project.  I have chosen MySQL to be database in
> Red Hat linux 7.0.  I writing a program to insert a
> value into the database in c language.  The data
> changes so i have to insert the data as a variable,
> but the database reports a error saying that the data
> is a column, the code is something like this..
> 
> int main(int argc, char **argv)
> {
> ..
> char* test;
> test="abcd";
> int res;
> MySQL *connection;
> 
> res=mysql_query(connection, "INSERT INTO tablename
> (userid) VALUES(test));
> 
> }
> 
> I get an error saying "Insert error 1054, unknown
> column 'test' in 'field-list'
> 
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail. 
> http://personal.mail.yahoo.com/
> 
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
> 
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
> 
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
> 
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail 
><[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
> 


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to