@@ -71,32 +71,42 @@ int main(int argc, char **argv)
71
71
printf ("Enter Password : " );
72
72
scanf ("%s" ,password );
73
73
74
- snprintf (query , MAX_STRING , "SELECT username,password FROM library.users WHERE username = '%s' AND password = '%s'" , username , password );
74
+ snprintf (query , MAX_STRING , "SELECT role FROM library.users WHERE username = '%s' AND password = '%s'" , username , password );
75
75
if (mysql_query (con , query ))
76
76
show_error (con );
77
77
78
78
MYSQL_RES * result = mysql_store_result (con );
79
+
80
+ int num_fields = mysql_num_fields (result );
81
+
82
+ MYSQL_ROW row ;
83
+
84
+ while ((row = mysql_fetch_row (result )))
85
+ {
86
+ for (int i = 0 ; i < num_fields ; i ++ )
87
+ {
88
+ printf ("%s " , row [i ] ? row [i ] : "NULL" );
89
+ }
90
+ printf ("\n" );
91
+ }
79
92
80
93
if (result -> row_count == 0 )
81
94
{
82
95
fprintf (stdout , "%s\n" , "Incorrect UserName or Password." );
83
96
}
84
97
else
85
98
{
86
- snprintf (query , MAX_STRING , "SELECT role FROM library.users WHERE username = '%s' AND password = '%s'" , username , password );
87
99
char users [5 ]= "user" ;
88
100
89
- if (strcmp (result ,users == 0 ) )
101
+ if (strcmp (row [ 0 ] ,users ) == 0 )
90
102
{
91
- database_connect ();
103
+ users_show ();
92
104
}
93
105
else
94
106
{
95
- users_show ();
107
+ database_connect ();
96
108
}
97
109
}
98
-
99
-
100
110
}
101
111
102
112
void database_connect (void )
@@ -111,7 +121,7 @@ void database_connect(void)
111
121
show_error (con );
112
122
113
123
114
- printf ("\n***************************** You Logged in as Admin*** ******************************" );
124
+ printf ("\n*************************You Logged in as Admin******************************" );
115
125
printf ("\n\nWhat do you want to do : \n" );
116
126
printf ("1). Add Users\n" );
117
127
printf ("2). Add Books Details \n" );
0 commit comments