How to write a script that stores website URLs in the database?

How to write a script that stores website urls in the database and if the url is already in the database, displays the message “That it is already there” when entering into the form?

I understand that the example is simple (15 minutes for an experienced programmer) do you need a small table and a script handler? But I don’t have time now. I would be grateful for ideas and advice. )

Answer 1, authority 100%

  1. Create a database with a table, for example “url” (id, url).
  2. Create a file – configuration (approx. config.php) put in it data for connecting to the database.
  3. Create a file – the script itself, connect the configuration file to it, create a form in it – add new URLs to the database. Also, when adding – put a check with a request for this url – SQL(WHERE url = $url).

Answer 2, authority 50%

Let’s start by saying that a script can NOT store anything in the database.

If you need to store the URL in the database, I see 2 approaches:

  • Before writing the URL, look for it in the database and if not, enter it
  • Make a UNIQUE key for the URL field in the database, and then check whether it was registered or not

Look at php.rufor how to do this specifically

Answer 3, authority 50%

I’ll elaborate on Sergey’s answer. After creating the UNIQUE key for the URL field, the following query should be executed:

$query = mysql_query("INSERT IGNORE INTO table (url) VALUES '" . $url . "'", $db);

Then depending on


display a message about successful addition (1), or failure (0).