touchasfen.blogg.se

Getamped2 checking duplicate login issue
Getamped2 checking duplicate login issue











Each time a new row is inserted, it adds 1 to the previous number, and stores that, so we don't have to worry about numbering, and can just let it do this itself. This basically allows us to let that field look after itself. You'll notice that I've also added something new here - AUTO_INCREMENT. To solve this, we can add an extra column, user_id, and make that the primary key (so when looking up the user record based on a post, we can find it quicker) CREATE TABLE users ( I've already mentioned that MySQL is faster at looking up numbers than strings, so this would mean we'd be spending time looking up strings when we didn't have to. However, when we wanted to store information about a post the user had made, we'd have to store the username with that post to identify that the post belonged to that user. For example, if we had a table for users, we could define it as CREATE TABLE users ( Within MySQL, keys (and espescially Primary Keys) are used to define relationships between two tables. This is because MySQL is quicker at looking up numbers than it is looking up text. Most of the time, it's useful to set the unique identifier for a row to be a number. A Primary key is a unique identifier for that row. This is because MySQL knows that the url is the Primary Key of the table.

getamped2 checking duplicate login issue

However, on subsequent runs, it'd die with Could not Insert Row 1. If you ran this, you'd find that on the first attempt, the script would die with the comment Could not Insert Row 2.

getamped2 checking duplicate login issue

$result2 = mysql_query("INSERT INTO links (url, last_visited) VALUES ('', NOW()", $conn) Then this would make mysql throw an error when I tried to insert the same value twice.Īn example in PHP would be $result = mysql_query("INSERT INTO links (url, last_visited) VALUES ('', NOW()", $conn) However, were my definition to change to CREATE TABLE links

GETAMPED2 CHECKING DUPLICATE LOGIN ISSUE CODE

This would allow me to add the same URL over and over again, unless I wrote some PHP code similar to the above to stop this happening. My definition might look something like this:- CREATE TABLE links

getamped2 checking duplicate login issue

Lets say I have a table where I want to just store all the URLs that are linked to from my site, and the last time they were visited. However, MySQL provides many ways to prevent this from happening in the first place.įirstly, you can mark a field as "unique". Of course, there are other ways of connecting to the database, like PDO, or using an ORM, or similar, so if you're already using those, this answer may not be relevant (and it's probably a bit beyond the scope to give answers related to this here!)

getamped2 checking duplicate login issue

It's likely that you'll already have a connection to a database, so you should use that rather than starting a new connection (replace $conn in the mysql_query command and remove the stuff to do with mysql_connect and mysql_select_db) I've written this out longhand here, with all the connecting to the database, etc. $number_of_rows = mysql_num_rows($result) ĭie('This URL already exists in the database') $result = mysql_query("SELECT * FROM links WHERE url = ''", $conn) ĭie('There was a problem executing the query') Your PHP code would look something like $conn = mysql_connect('localhost', 'username', 'password') To answer your initial question, the easiest way to check whether there is a duplicate is to run an SQL query against what you're trying to add!įor example, were you to want to check for the url in the table links, then your query would look something like SELECT * FROM links WHERE url = ''











Getamped2 checking duplicate login issue