Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question [Some Help] Telling PHP to identify pre-existing URLS.

    Hello,

    I would like some help trying to code a little script. However, I do not want you guys to do it for me, simply direct me to a source where I can learn myself. I appreciate it in advanced.

    Here is my problem:

    - I would like to create a little script that will let users submit URLS and store them on a MYSQL database. When they log back into their account they will have the URLS displayed for them. Now, here is the thing I would like the submit feature to do. When they go to submit more URLS, I would like PHP to tell the user that they have submitted that specific URL already, and have it display the URL that is doubled.

    If possible I would like them to be able to submit some URLS, and have php check them, and delete double URLS while it's being submitted and processed to the MYSQL table.

    Thank you again, I would like to learn! So if anyone could link me a source where I can do this I'd appreciate it fully.

    Kindest Regards,
    Qode

  • #2
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    This is quite simple and easy to do, if you take a look at it from a distance.

    • A user submits X url
    • You query your database for X url
    • Either X exists, or it doesn't
    • If X exists, display error and url
    • If X doesn't exist, insert X into database


    You will need your user submitted $_POST variable (URL), a MySQL connection, a MySQL Query, and an if, else statement

  • #3
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    332
    Thanks
    2
    Thanked 47 Times in 46 Posts
    You need to learn SQL - preferably MySQL - as PHP cannot do this on its own.

    MySQL links:

    SQL - http://www.w3schools.com/sql/default.asp
    PHP and MySQL - http://www.w3schools.com/php/php_mysql_intro.asp

    Learn SQL first then learn how to use MySQL though PHP.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Assuming you are running a many to one (ie: replicated URL's are allowed since if you had two people with the same URL that doesn't mean that one won't delete or modify it and you don't want it to change both user's), then stopping it is a simple matter of using the INSERT IGNORE syntax. That is, after being given 100 records for example, if it finds 3 that are duplicates it will reject these three silently and continue with insertion instead of failing.

    If the record is already saved, you can issue a SELECT first. I don't recommend doing that if you are using a batch insertion though as that will really cause a lot of overhead.

    If its not yet saved, you can detect duplicates by using array_count_values. This creates an indexed 'value' as the key, and the value is the number of times that appears. If its > 1, then you have duplicates.

    IMO, these can all be successfully ignored without even notifying the user. Simply removing them is sufficient.

  • #5
    New Coder
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If I pay you 30.00 will you make me a tiny script? :3

  • #6
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    Send me a PM, and you got a deal

  • #7
    New Coder
    Join Date
    Dec 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I actually made it myself. Sorry guys! I get lazy sometimes, and I throw money too people when I don't want too do something. I been this way since I was born, I procrastinate too much lmfao.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •