Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6015945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:54:45+00:00 2026-05-23T02:54:45+00:00

I have created a C program which updates user name with client input, but

  • 0

I have created a C program which updates user name with client input, but i could not update username, can anyone help me to resolve this.

Here is my code

#include<stdio.h>
#include<mysql.h>

#include<string.h>

#include<stdlib.h>

main()

{

    int i,num_fields;

    int len,choice;

    char name[50],search[50],ename[50];

    char query[200];
    MYSQL *conn;
    MYSQL_RES *result;
    MYSQL_ROW *row;
    MYSQL_FIELD *field;
    int ret;
    char stat[50] = "INSERT INTO Users VALUES('%s')";
    char updatename[200] = "UPDATE Users SET name='%s' WHERE name='%s'";
    conn = mysql_init(NULL);
    ret=mysql_real_connect(conn,"localhost","root","bisptop","testdb",0,NULL,0);
    scanf("%d",&choice);
    switch(choice)
    case 1:
    {
      insert code
    }
    case 2:
    {
      display code
    }
    case 3:
            {
                    printf("edit name");
                    scanf("%s",search);
                    mysql_query(conn,"SELECT * FROM Users");
                    result=mysql_store_result(conn);
                    num_fields=mysql_num_fields(result);
                    while((row=mysql_fetch_row(result)))
                    {
                            for(i=0;i<num_fields;i++)
                            {
                                    if(strcmp(search,row[i])==0)
                                    {
                                            //printf("%s",row[i]);
                                            printf("Enter new name\n");
                                            scanf("%s",ename);
                                            len=snprintf(query,sizeof(updatename)+strlen(ename),updatename,ename);
                                            //printf("%d",len);
                                            printf("%s\n",query);
                                            mysql_query(conn,query);
                                            mysql_close(conn);
                                    }
                            }
                    }
                    break;
            }
    }

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:54:46+00:00Added an answer on May 23, 2026 at 2:54 am
    len=snprintf(query,sizeof(updatename)+strlen(ename),updatename,ename);
    

    If you want to update the name, shouldn’t this line contain both the old name and the new name? How else would we know what name to update?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an AppleScript program which creates XML tags and elements within an Adobe
I have a web service I'm trying to load test. I created a program
I have a program that creates a Windows user account using the NetUserAdd() API
I have created a C# Windows Forms application which I've attempted to make as
Scenario : There is a legacy program (Not sure what language) and I have
Unix gurus! I have a Java program which passes some parameters to a Servlet
I want to create a C# program to provision Windows Mobile devices. I have
I have been tasked with creating a program what will create take files in
I have a problem with my WPF program. I'm trying to create an object
In a C# program, I have an abstract base class with a static Create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.