l.
> 
> -----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'
> 

I don't program in c myself, but if you were doing this from the mysql
utility, the value of your variable test, would have to be in single quotes.
(ie. INSERT INTO tablename (userid) VALUES ('<data to insert>') )

I am guessing that your program is trying to put the raw word test into the
database, not the value of your variable.

Also looks like you forgot to close the double quote.

Do whatever you have to do to get your variable to interpolate inside the
query string. 

Maybe build the query in a local variable and insert the variable into the
second parameter of mysql_query?

Querystring = "INSERT INTO tablename (userid) VALUES ('".test."')";

(I don't know what the c concatenation operator is,php uses the '.', but you
should build your query like this to put the value of test into the query
string. I also don't know the behavior of double quotes in strings, and
variables within them within c)


If you copied and pasted that query as is into the mysql client, you would
get the same error.


---------------------------------------------------------------------
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