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

  • SEARCH
  • Home
  • 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 8242617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:13:50+00:00 2026-06-07T21:13:50+00:00

I’m trying to create a column and make it count the number of tries

  • 0

I’m trying to create a column and make it count the number of tries of insert that the user make.

An example would make things much clearer :

+-------+----------------------------------+--------------+
| text  |            md5                   | insert_times | 
+-------+----------------------------------+---------+----+
| 123   | 202cb962ac59075b964b07152d234b70 |     834      |  
| abc   | 900150983cd24fb0d6963f7d28e17f72 |     923      |      
+-------+----------------------------------+--------------+

where text is a primary key.
Whenever a user tries to inserts 123 (using INSERT IGNORE to not get error messages because 123 already exists), the insert_times would increase by 1, keeping track of number of tries of inserting an already existing text in the table.

Any ideas on how to make it?
I cannot make triggers because my db host (godaddy) doesn’t allow triggers.
If not possible to do in mysql, can I pull it off with the help of php?

  • 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-06-07T21:13:53+00:00Added an answer on June 7, 2026 at 9:13 pm

    To do this within a single, simple query, simply use the ON DUPLICATE KEY UPDATE function within MySQL. With this you simply do your INSERT followed by what needs to be updated in the ‘duplicate’ row. For example:

    INSERT INTO tbl (text, md5, insert_times) VALUES ('abc', {MD5}, 0}
    ON DUPLICATE KEY UPDATE insert_times+1;
    

    However, I personally prefer the PHP approach, as in most of my queries things usually aren’t as cut and dry as a simple update:

    $res = mysql_query(sprintf("SELECT text FROM tbl WHERE text = '%s'", $text));
    if (mysql_num_rows($res) != 0)
    {
        mysql_query(sprintf("UPDATE tbl SET insert_times+1 WHERE text = '%s'", $text);
    }
    else
    }
        mysql_query(sprintf("INSERT INTO tbl SET text = '%d', md5 = '%s'", $text, $hash);
    }
    

    This method leaves for more room to do trigger other events/ functions as well, if needed.

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.