2

so I have a MySQL Database and I want to write an IP address to a specific and existing row.

For example, username "Johnny" logs in and the system will go to the row for username "Johnny" and write to column ipaddress.

Currently I only know how to create an entire new row using:

queryStr = "INSERT INTO webappdemo.userregistration(firstname,middlename,lastname,email,phonenumber,username,slowHashSalt)" +
           "VALUES(?firstname, ?middlename, ?lastname, ?email, ?phonenumber, ?uname, ?slowHashSalt)";

So the question is how to write to an existing row by filtering via username and writing to a specific column.

Thanks.

sujith karivelil
  • 28,671
  • 6
  • 55
  • 88
Marvinatorrr
  • 103
  • 1
  • 3
  • 15

2 Answers2

2

Hope that you are familiar with SQL UPDATE queries. Which can be used for modifying an existing row in a table, So here you have to use UPDATE Statements; Let me add a sample as well, Your code looks like this:

string querySql = "UPDATE webappdemo.userregistration SET" +  
                  " ipaddress=@ip Where user_name=@user";
// Add necessary parameters and execute the query
// It will update that particular row
sujith karivelil
  • 28,671
  • 6
  • 55
  • 88
1

you are looking for an UPDATE statement with a WHERE clause http://dev.mysql.com/doc/refman/5.7/en/update.html

Alexander Taran
  • 6,655
  • 2
  • 39
  • 60