help on gtk with mysql



Hi
       I am Prathibha.I am using gtk with database as mysql.I have written the c api for connecting to the database.The problem is I need to access the string that is the currently selected option of the combo box.the null value is entering into database for the combo box.

I am attaching the code which i have done.
please help me.
 
 
#include <gtk/gtk.h>
#include <stdlib.h>
#include <mysql.h>
#include <glib.h>


char *p;
GtkEntry *entry_box;

gint delete_event(GtkWidget *widget, GdkEvent event, gpointer data)
{
return FALSE;
}
void end_program(GtkWidget *widget, gpointer data)
{
gtk_main_quit();
}

void doSQL(MYSQL *conn,char *command)
{
printf("%s\n",command);
mysql_query(conn,command);
printf("result: %s\n",mysql_error(conn));
}

a()

{
MYSQL *conn;
conn=mysql_init(NULL);
if(mysql_real_connect(conn,"localhost",NULL,NULL,"ravi",0,NULL,0))
{
printf("connection made\n");
g_object_get(combo,"text",&p,NULL);
p=strdup(p);

doSQL(conn,"INSERT INTO test(id )VALUES("%s"),p");

}
}


int main(int argc, char **argv)
{
GtkWidget *window;
GtkWidget *box;
GtkButton *b;

gtk_init(&argc,&argv);
window=g_object_new(GTK_TYPE_WINDOW,"title","dataentry
widget","border-width",12,"default-width",800,NULL);
g_signal_connect(window,"delete_event",G_CALLBACK(delete_event),NULL);
g_signal_connect(window,"destroy",G_CALLBACK(end_program),NULL);
box=gtk_vbox_new(FALSE,0);
combo=g_object_new(GTK_TYPE_COMBO,"text","",NULL);

b=g_object_new(GTK_TYPE_BUTTON,"label","INSERT",NULL);
g_signal_connect(b,"clicked",G_CALLBACK(a),NULL);
gtk_container_add(GTK_CONTAINER(window),box);
gtk_box_pack_start_defaults(GTK_BOX(box),combo);
gtk_box_pack_start_defaults(GTK_BOX(box),b);
gtk_widget_show_all(GTK_WIDGET(window));
gtk_main();
return 0;
}
 
 
i am not getting the value in the combo box.
 
please help me.
 
regards
prathibha.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]