SQL Insert query is executed twice
I can't see anything in your code that would execute it twice. I'd assume that it is being called twice. Put a break point at addNewComment
and if it is being called twice look at the stack traces to see where it is being called from on both occasions.
Maybe you have an event being called twice for example. This can happen in ASP.NET if you both have auto wiring of events enabled and have wired the event up explicitly.
By the way you should definitely use parametrized queries not string concatenation. I'm assuming that comment is user supplied input? In which case you are setting yourself up for a SQL injection attack with the code you have shown.
PDO Inserts data twice on single query
Thanks to @James Taylor for the suggestion of .htaccess
file. The problem was hiding in RewriteRule and parameter QSA
.
PDO inserting the same data twice
->query
executes it one time, ->execute
does it a second time. You need to remove the execute
.
Row inserts twice with one load
May be not an answer to your question, but I think you need to optimize your statements. Otherwise you can have like thousands of records with repeating ips and 0 or 1 times visited.
- IP address - varchar -(UNIQUE KEY)
- Times visited. - mediumint -
Then you could make it easier (UPDATED):
$ip = $mysqli->real_escape_string($_SERVER['REMOTE_ADDR']) ;
$update = "INSERT INTO visits (ip, times_visited) VALUES ('{$ip}', 1)
ON DUPLICATE KEY UPDATE times_visited = times_visited+1 ; " ;
Related Topics
PHP Glob - Scan in Subfolders For a File
How to Get JavaScript Function Data into a PHP Variable
Best Way to Completely Destroy a Session - Even If the Browser Is Not Closed
Preserve Key Order (Stable Sort) When Sorting With PHP'S Uasort
Import CSV File Directly into MySQL
PHP Is Confused When Adding and Concatenating
How to Access Dynamic Variable Names in Twig
Initializing PHP Class Property Declarations With Simple Expressions Yields Syntax Error
Access Controller Method from Another Controller in Laravel 5
PHP Curl Not Working - Wamp on Windows 7 64 Bit
How to Read Last Lines (I.E. "Tail") from a File Using PHP
Read Each Line of Txt File to New Array Element
Convert Timestamp to Readable Date/Time PHP