Reputation: 322
I am developing Android application that sends HTTP requests
to a server using php and mysql
.
The user has to fill in two fields. let's say A and B these will be added to two columns of a table (col A and col B. However, I want to add the contents of A to B after that. it works fine.
I am having a problem in checking the duplicates of A in B. The result i want is A as the user enters and B of the content of A+B with no duplicates.
This is what i am using
$A = $_POST['A'];
$last_inserted_id = mysql_insert_id();
$updateTable = mysql_query("UPDATE Table SET B=IFNULL(CONCAT(B, '$A'), '$A')WHERE _id='$last_inserted_id'");
To make it clearer, B contains only words not a sentence, however, A is a sentence.
so I stemmed the sentence A .. for example A="I want to learn programming" -$A= "learn programming".
So if B is programming .. the final result must be learn and programming only . Now I'm getting learn programming learn.
Upvotes: 0
Views: 110
Reputation: 211580
If this record was just inserted, you probably could've put that data in there in the first place. If this is a subsequent request, then mysql_insert_id()
cannot be trusted, as other records might've been inserted.
Is there anything that precludes you from putting the data in there in the first place?
If you want a method to append to an existing field, you could simplify this by defaulting B
to be an empty string, making the IFNULL
check on your CONCAT
call redundant.
Upvotes: 1