Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when i click on like button btn text not changing

record successfully added to db

but btn not changing to unlike

And one more problem when i hit like btn page moves to top of timeline

i using update panal for like btn

What I have tried:

my coding

if (Session["user"] != null)
        {

            con.Open();
            { 
            
                string inq="insert into main (adlikes,adid) values ('"+Session["id"]+"','"+lblide.Text.ToString()+"')";

                SqlCommand cmd = new SqlCommand(inq, con);
                int i=cmd.ExecuteNonQuery();

                if (i == 1)
                {

                    btnlike1.Text = "Unlike";

                }
                else
                {

                    Response.Write("Sorry there is problem Please Report this problem to Experts ");
                
                }
                con.Close();
               

            }


        }


       
    }
Posted
Updated 26-Aug-17 6:26am
Comments
Michael_Davies 26-Aug-17 12:37pm    
Use the debugger and check the value of i to be certain it returned 1.

1 solution

Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900