I am creating a login/sign up form using C++ and MySQL on Visual Studio 2019, despite the fact that the sign up works and actually stores the information the user inputs into the databse. While logging into the application, even if the password is correct, always the "username or password is incorrect!\n try again..." is always outputted when running the application. I haven't tried much because I am not even able to see the error in the first place.
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
try
{
String^ constr = "Server=127.0.0.1;Uid=root;Pwd=;Database=database";
MySqlConnection^ con = gcnew MySqlConnection(constr);
String^ password = textBox8->Text;
String^ username = textBox1->Text;
MySqlCommand^ cmd = gcnew MySqlCommand("select * from register_table where Username='" + username + "' and Password='" + password + "';", con);
MySqlDataReader^ dr;
con->Open();
try
{
dr = cmd->ExecuteReader();
int count = 0;
while (dr->Read())
{
count += 1;
}
if (count == 1)
{
MessageBox::Show("Login successful, Congratulations...");
}
else
{
MessageBox::Show("username or password is incorrect!\n try again...");
}
}
catch (Exception^ ex)
{
MessageBox::Show(ex->Message);
}
con->Close();
}
catch (Exception^ ex)
{
MessageBox::Show(ex->Message);
}
}
For anyone interested, after debugging the application, I saw that for some reason it confused the password and username. So I just switched their places and it worked, in this way that is:
MySqlCommand^ cmd = gcnew MySqlCommand("select * from register_table where Username='" + password + "' and Password='" + username + "';", con);
Kind of weird, but hey it works!
I'm trying to insert data into mysql database.
I'm using mysqlConnector.
But after I confirm insertion with my code.
Debugger returns Index was outside the bounds of the array
Here is my code of insertion:
if (co.OpenConnection() == true)
{
string query = "INSERT INTO inventory (flItem) VALUES('" + ItemName.Text + "');";
MySqlCommand cmd = new MySqlCommand(query, co.connection);
//MySqlDataReader reader = cmd.ExecuteReader();
cmd.ExecuteReader();
await DisplayAlert("TEST", cmd.CommandText, "OK");
await Navigation.PushAsync(new AppShell());
}
Thanks for any help in advance.
I am trying to plot a scatterplot chart with the data from my database. I am retrieving the data from my servlet which when I tried to print out, it gives me a JSON object. But, in my jsp page, it gives me an undefined value or null. Can someone help me out with this? Thank you.
Servlet
try {
// Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");
// Open a connection
Connection conn = (Connection) DriverManager.getConnection(DB_URL, USER, PASS);
// Execute SQL query
Statement stmt = (Statement) conn.createStatement();
String sql;
sql = "SELECT userName as userName, fpogx, fpogy\r\n"+
"FROM affecttutor.gazedata WHERE fpogv = 1;";
/*sql = "select exercise_working_on as exeWork, sum(no_of_errors) as countErr, idtopic\r\n" +
"from affecttutor.fexdb left join affecttutor.exercises on affecttutor.fexdb.exercise_working_on=affecttutor.exercises.idexercises\r\n" +
"where user_id LIKE '%student08%' && no_of_errors!=0 && exercise_working_on!=0 group by exeWork;";*/
JSONArray list = new JSONArray();
ResultSet rs = stmt.executeQuery(sql);
// Extract data from result set
while(rs.next()) {
//Retrieve by column name
JSONObject object=new JSONObject();
float fpogx = rs.getFloat("fpogx");
float fpogy = rs.getFloat("fpogy");
String userName = rs.getString("userName");
object.put("fpogx", fpogx);
object.put("fpogy", fpogy);
object.put("userName", userName);
list.put(object);
}
out.println(list);
System.out.println(list);
// Clean-up environment
// rs.close();
//stmt.close();
//conn.close();
} catch(SQLException se) {
//Handle errors for JDBC
se.printStackTrace();
} catch(Exception e) {
//Handle errors for Class.forName
e.printStackTrace();
}
JSP
d3.json("analysisDataServlet", function(error, data) {
console.log(data);
if (error) throw error;
JSON
[{"fpogy":0.0348300002515316,"fpogx":-2.7372400760650635,"userName":"student01"},{"fpogy":0.03328999876976013,"fpogx":-2.73757004737854,"userName":"student01"},{"fpogy":0.03189000114798546,"fpogx":-2.73786997795105,"userName":"student01"},{"fpogy":0.5096700191497803,"fpogx":0.4750800132751465,"userName":"student01"},{"fpogy":0.5096700191497803,"fpogx":0.4750800132751465,"userName":"student01"},{"fpogy":0.5096700191497803,"fpogx":0.4750800132751465,"userName":"student01"},{"fpogy":0.5096700191497803,"fpogx":0.4750800132751465,"userName":"student01"},{"fpogy":0.5096700191497803,"fpogx":0.4750800132751465,"userName":"student01"},{"fpogy":0.5012699961662292,"fpogx":0.4617300033569336,"userName":"student01"},{"fpogy":0.5012699961662292,"fpogx":0.4617300033569336,"userName":"student01"},{"fpogy":0.5012699961662292,"fpogx":0.4617300033569336,"userName":"student01"},{"fpogy":0.5012699961662292,"fpogx":0.4617300033569336,"userName":"student01"},{"fpogy":0.5012699961662292,"fpogx":0.4617300033569336,"userName":"student01"},{"fpogy":0.4968700110912323,"fpogx":0.4556199908256531,"userName":"student01"},{"fpogy":0.4968700110912323,"fpogx":0.4556199908256531,"userName":"student01"}]
<%#page import="java.io.PrintWriter"%>
<%#page contentType="text/html; charset=UTF-8"%>
<%#page import="newpackage.ChartDataController,java.util.*"%>
<%
String json=ChartDataController.getChartData();
response.setContentType("application/json");
response.getWriter().write(json);
%>
i just wander if there is away to check MySql asp Table if its Cells has Values or Not .
i'v used this to return if Database has Row/Record there
string ConnectionString = #"Server=MYSQL5011.Smarterasp.net;Database=db_9d6c52_ahmed;Uid=9d6c52_ahmed;Pwd=******;";
MySqlConnection GetConnection = new MySqlConnection(ConnectionString);
GetConnection.Open();
string VoiceorScreenSearch = "Select User_Voice ,User_Screen From User where User_Stat=#UserStat";
MySqlCommand Comand = new MySqlCommand(VoiceorScreenSearch, GetConnection);
Comand.Parameters.AddWithValue(#"UserStat", key);
MySqlDataReader ReadData = Comand.ExecuteReader();
if (ReadData.HasRows)
{
hasrowsornot = true;
}
but i need it to return if Cell[1] is null or Has data !, My Cells Datatype is BLOB
and tips of doing this ? , will be helpful
Thanks
You can try like this:
if (!ReadData.IsDbNull(yourfield)) {
var value = ReadData.GetString(yourfield);
// some code
}
Here headers are also inserting into database .here uploading the csv file with comma separated data
string Feedback = string.Empty;
string connString = ConfigurationManager.ConnectionStrings["DataBaseConnectionString"].ConnectionString;
using (MySqlConnection conn = new MySqlConnection(connString))
{
var copy = new MySqlBulkLoader(conn);
conn.Open();
try
{
copy.TableName = "BulkImportDetails";
copy.FileName = fileName;
copy.FieldTerminator = ",";
copy.LineTerminator = #"\n";
copy.Load();
Feedback = "Upload complete";
}
catch (Exception ex)
{
Feedback = ex.Message;
}
finally { conn.Close(); }
}
return Feedback;
Use the NumberOfLinesToSkip property to skip the first line, like so:
copy.NumberOfLinesToSkip = 1;
The use of this property is clearly shown in the documentation for MySQLBulkLoader. You must make a habit of reading the documentation to resolve your queries before you post a question here.