简体   繁体   English

如何使用 php 将 user_id 存储在 MySQL 数据库中

[英]How to store user_id's in MySQL database using php

I have a website which generates each visitor a referral link (ex. http://mysite.com/?ref=12345678 ).我有一个网站,它为每个访问者生成一个推荐链接(例如http://mysite.com/?ref=12345678 )。 The actual referral id (12345678) is a unique 8 character ID (using uniqid() ).实际的推荐 ID (12345678) 是唯一的 8 个字符 ID(使用uniqid() )。

I then just add the ID to the end of http://example.com/?ref=....然后我只需将 ID 添加到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.我正在尝试找到一个可以连接到我的 MySQL 数据库的脚本,检查 id 是否存在,如果不存在,请将其输入表中。

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 help with that.我猜我需要实现一个cookie来检查id是否存在,所以我真的不需要帮助。 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 .这是一个很好的起点: 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.该文档将提供通过 PHP 连接到 MySQL 数据库和插入数据所需的信息。 Specifically, you will need to use the mysql_query() function.具体来说,您将需要使用 mysql_query() function。

You can use the "UPDATE INTO" syntax to ensure that you do not create duplicate rows.您可以使用“UPDATE INTO”语法来确保不会创建重复的行。 Please see http://dev.mysql.com/doc/refman/5.0/en/update.html for more information.请参阅http://dev.mysql.com/doc/refman/5.0/en/update.html了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM