Please take a look. when I like each article, each ip address can only like each article once. how can I implement the code.

Source: Internet
Author: User
Please take a look. when I like each article, each ip address can only like each article once. how can I implement the code. // Frontend ajax submits data
           
 {$ Article. love}

Script function change_love (article_id) {// var Lastsend = document. getCookie ('ecs _ auction_Lastsend _ '+ article_id); // alert ('thumb up successfully'); $. ajax ({url: 'Article. php ', // background processing path type: 'post', // post submission method data: {id: article_id}, // Thumb up article id success: function (data) {// if (data = 1) {// success }});} script



// Update the database in the background and determine whether the ip address exists
$ Realip = getip (); // echo $ realip; modifyipcount ($ realip); @ $ love = $ _ POST ['id']; if (isset ($ love )) {$ query = "SELECT * FROM ecs_article_love where article_id = '". $ article_id. "'"; $ result = mysql_query ($ query); $ row = mysql_fetch_row ($ result); // dump ($ row); $ ip1 = $ row [2]; $ ip2 = $ realip; // echo $ ip; if (! Empty ($ row) & strcmp ($ ip1, $ ip2) = 0) {echo "script alert ('IP already exists ') script";} else {// $ iptime = time (); // $ day = date ('Y-m-D'); // if ($ row [article_id]! = $ Article_id | $ row [ip]! = '') $ Query =" insert into ecs_article_love (ip, article_id) VALUES ('". $ ip2 ."','". $ article_id. "')"; mysql_query ($ query); echo "script alert ('thumb up successful') script" ;}}


// List of ip addresses


Reply to discussion (solution)

In my opinion, design a table with only two fields: Article id, user ip, and two fields as the joint primary key.
Each time a user accesses and queries, he or she finds that he or she likes. You can just like it if you don't find it. because it is a joint primary key, you can only insert one entry, so you have made a limit through the database. View the number of likes in the article. you can directly use the where article id to count.

Therefore, the order of the Union primary key is: Article id, user ip address

In my opinion, design a table with only two fields: Article id, user ip, and two fields as the joint primary key.
Each time a user accesses and queries, he or she finds that he or she likes. You can just like it if you don't find it. because it is a joint primary key, you can only insert one entry, so you have made a limit through the database. View the number of likes in the article. you can directly use the where article id to count.

Therefore, the order of the Union primary key is: Article id, user ip address

How can I return the information to be popped up after the ajxa is submitted successfully and output 1 directly?

$ Query = "SELECT * FROM ecs_article_love where article_id = '$ article_id' and ip = '$ realip '";

$ Query = "SELECT * FROM ecs_article_love where article_id = '$ article_id' and ip = '$ realip '";

How can I pop up the successful thumb ups message after ajax is submitted successfully. Directly output echo 1?

Yes! Echo 1;

Yes! Echo 1;

It doesn't seem to work.

What does it mean ???

What does it mean ???

$ Ip1 = $ row [2]; $ ip2 = $ realip; // echo $ ip; if (! Empty ($ row) & strcmp ($ ip1, $ ip2) = 0) {// echo "script alert ('IP already exists ') script"; echo 1;} else {// $ iptime = time (); // $ day = date (

Url: 'Article. php ', // background processing path type: 'post', // post submission method data: {id: article_id}, // Thumb up article id success: function (data) {// data returns success if (data = 1) {// successful alert ('thumb up successful! ');}}});
Is this incorrect?

It is generally difficult to debug ajax programs. without tools, you need to add code to check data
Success: function (data) {// data returned successfully
Alert (data); // as long as there is no error in ajax, there will always be a pop-up window
If (data = 1) {// succeeded
Alert ('thumb up successful! ');
}
}

Php end
If (! Empty ($ row) & strcmp ($ ip1, $ ip2) = 0 ){
Echo 1;
} Else {
Echo 0;
}
What are output by each branch, so that you can easily find out if there is a problem with the process.

It is generally difficult to debug ajax programs. without tools, you need to add code to check data
Success: function (data) {// data returned successfully
Alert (data); // as long as there is no error in ajax, there will always be a pop-up window
If (data = 1) {// succeeded
Alert ('thumb up successful! ');
}
}

Php end
If (! Empty ($ row) & strcmp ($ ip1, $ ip2) = 0 ){
Echo 1;
} Else {
Echo 0;
}
What are output by each branch, so that you can easily find out if there is a problem with the process.

There is a pop-up window, why is no message output for successful thumb ups?

Check the submitted data and the obtained data.
If no problem occurs, check the returned data.

It is best to write the received data to log in php for convenient check.
Then display the returned data in js.

Check the submitted data and the obtained data.
If no problem occurs, check the returned data.

It is best to write the received data to log in php for convenient check.
Then display the returned data in js.

I can't find any problem. alert (data); all of them have data.

The preceding html and js code indicates that the code for returning data to ajax is incorrect (the entry point is incorrect)
The following php error message indicates that your program is not fault tolerant.

Solve these problems first.

The preceding html and js code indicates that the code for returning data to ajax is incorrect (the entry point is incorrect)
The following php error message indicates that your program is not fault tolerant.

Solve these problems first.

The portal is incorrect ?? How to Write

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.