Dear. everybody.

when i progress the developing some functions using mysql db with vc++2005, i have the following problems

i connected mysqldb and i runned the query to insert some records to my table in the DB, but i cant success in inserting.

my sample code is followed as :

char sqlString[1024];

sprintf(sqlString,"INSERT INTO myTable('StaffID','Name','Birthday','PhotoURL')  VALUES('%d','%s','%s','%s')",'3','playboy','10-19-2009','c:\myphoto.jpg');

int m_Query_State = mysql_query(m_pConnection, sqlString);
    if (m_Query_State != 0)
    {
        fprintf(stderr, "Mysql query error : %s", mysql_error(&m_Conn));
        return ;
    }

when i run this statement , m_Query_State Value =1. so the run of the code was faild.

how can i solve this problem?
if someone experienced the connectivity mysqldb with vc++2005, please kindly teach me.

i'll really appreciate if you help me.

Edited 3 Years Ago by Dani: Formatting fixed

Let me start by mentioning that this is C and not C++.

this is wrong in your code:

sprintf(sqlString,"INSERT INTO myTable('StaffID','Name','Birthday','PhotoURL') VALUES('%d','%s','%s','%s')",'3','playboy','10-19-2009','c:\myphoto.jpg');

Strings should be surrounded with double-quotes, not single, so "playboy" instead of 'playboy' etc.
Also use a forward-slash when using filepaths (c:/blah). The backslash indicates an escape-character.

The more C++ way to do this would be:

std::string sqlString = "INSERT INTO myTable('StaffID','Name','Birthday','PhotoURL') VALUES('3,'playboy,'10-19-2009','c:/myphoto.jpg')";

int m_Query_State = mysql_query(m_pConnection, sqlString.c_str());

Also use code-tags when posting code here

Edited 7 Years Ago by Nick Evan: n/a

dear niek_e

thank you for your kindness response.

but the problem is still remained.

actually i used c syntax ,not c++.
and i also know that string should be surrounded with double-quotes, not single, but in this statement, how can i coding your description?

[LIST=1]
[*]char sqlString[1024];

[*]sprintf(sqlString,"INSERT INTO myTable('StaffID','Name','Birthday','PhotoURL') VALUES('%d','%s','%s','%s')",'3',"playboy","10-19-2009",[B]"c:/myphoto.jpg"[/B]);

[*]int m_Query_State = mysql_query(m_pConnection, sqlString);
[*]if (m_Query_State != 0)
[*]{
[*]fprintf(stderr, "Mysql query error : %s", mysql_error(&m_Conn));
[*]return ;
[*]}
[/LIST]

Edited 7 Years Ago by starboy: n/a

actually i used c syntax ,not c++.

Then why did you post in the C++ forum and not in the C forum? I'll ask if the thread can be moved.

and i also know that string should be surrounded with double-quotes, not single, but in this statement, how can i coding your description?

Why did you use singles if you knew it was wrong? Anyway, what's your new error-message?

hello everybody am new n i need to develop myself in computer programming pls i need help

i need to develop myself in computer programming

#include <iostream>

int main()
{
    std::cout << " O\n\\ /  <--- ME\n |\n/ \\";
    std::cin.get();
}

Done.

dear mr niek_e, sorry i confuse you.
the error is same with first case.
that is, m_Query_State value is still 1.
so ,in above codes what is the wrong one?

here, m_pConnection is the handle indicating MySQL db.
it is already connected and it is not null.

but i have still same problem.
please kindly teach me again.

char sqlString[1024];
    sprintf(sqlString,"INSERT INTO myTable('StaffID','Name','Birthday','PhotoURL') VALUES('%d','%s','%s','%s')",'3',"playboy","10-19-2009","c:/myphoto.jpg");
    int m_Query_State = mysql_query(m_pConnection, sqlString);
    if (m_Query_State != 0)
    {
    fprintf(stderr, "Mysql query error : %s", mysql_error(&m_Conn));
    return ;
    }

Edited 7 Years Ago by starboy: n/a

So what does this line output: fprintf(stderr, "Mysql query error : %s", mysql_error(&m_Conn)); ?

the line is for error processing.

I know.. I meant: What is the output from that line? It says something like: Mysql query error : [blabla] and I want to know what the blabla is.

I know.. I meant: What is the output from that line? It says something like: Mysql query error : [blabla] and I want to know what the blabla is.

nothing,
mysql_error(&m_Conn) does not return any values.
so i cannot find the wrong reason.

This article has been dead for over six months. Start a new discussion instead.