Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-27-2012, 05:10 AM   PM User | #1
qode
New Coder

 
Join Date: Dec 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
qode is an unknown quantity at this point
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
qode is offline   Reply With Quote
Old 12-27-2012, 03:48 PM   PM User | #2
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
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
TFlan is offline   Reply With Quote
Old 12-27-2012, 04:19 PM   PM User | #3
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
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.
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk
Redcoder is offline   Reply With Quote
Old 12-27-2012, 04:29 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 12-28-2012, 04:41 PM   PM User | #5
qode
New Coder

 
Join Date: Dec 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
qode is an unknown quantity at this point
If I pay you 30.00 will you make me a tiny script? :3
qode is offline   Reply With Quote
Old 12-28-2012, 07:29 PM   PM User | #6
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
Send me a PM, and you got a deal
TFlan is offline   Reply With Quote
Old 12-31-2012, 02:49 AM   PM User | #7
qode
New Coder

 
Join Date: Dec 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
qode is an unknown quantity at this point
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.
qode is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:59 PM.


Advertisement
Log in to turn off these ads.