开发者

How to store user_id's in MySQL database using php

开发者 https://www.devze.com 2023-03-11 01:25 出处:网络
I have a website which generates each visitor a referral link (ex. http://mysite.com/?ref=12345678). The actual referral id (12345678) is a unique 8 character ID (using uniqid() ).

I have a website which generates each visitor a referral link (ex. http://mysite.com/?ref=12345678). The actual referral id (12345678) is a unique 8 character ID (using uniqid() ).

I then just add the ID to the end of http://example.com/?ref=....

I am trying to find a script which can connect to my MySQL database, check if the id exists, and if it doesn't, enter it into the table.

If it does exist it shouldn't do anything.

I am guessing that I need to implement a cookie to check if the id exists, so I don't really need h开发者_运维百科elp with that. I'm just confused to how to make the script I mentioned above.

I'm trying to make the table look like this:

Unique ID
---------
3af456yT
Sa32xs21
9af456yT
8a78Fs21
1wsd4Fav
7f3Xv5Bd


Here is a great place to start: http://php.net/manual/en/book.mysql.php. The documentation will provide the information you need to connect to a MySQL database via PHP and to insert data. Specifically, you will need to use the mysql_query() function.

You can use the "UPDATE INTO" syntax to ensure that you do not create duplicate rows. Please see http://dev.mysql.com/doc/refman/5.0/en/update.html for more information.

0

精彩评论

暂无评论...
验证码 换一张
取 消