PHP avoids adding duplicate record instance code to MySql. I recently wrote an English search thief. in order to make the spider better enjoy the fun of the link, I used the warehouse receiving processing to write the latest search to mysql, at the same time, I called these thieves who recently wrote an English search on the homepage. in order to make the spider better enjoy the fun of the link, I used the warehouse receiving process to write the latest search to mysql, at the same time, calling the query data on the home page can achieve the effect of website maps, but the drawback also arises, that is, the problem of repeated records.
Find an instance on the Internet and modify it. the code is published as follows:
Copy to ClipboardReference: [www.bkjia.com] $ Link = mysql_connect ('localhost', 'root', '000000'); // Obtain the MySQL database connection.
$ Username = $ _ GET ["name"]; // GET the data transmitted from the client form
$ Q = "select * from usertable where user_name = '$ username '";
Mysql_query ("set names gb2312"); // avoid Chinese garbled characters
$ Rs = mysql_query ($ q, $ link); // query a database
$ Num_rows = mysql_num_rows ($ rs); // The total number of rows in the query result.
If ($ num_rows = 0)
// Copy the website bkjia.com to reject malicious collection of liehuo.net
{
$ Exec = "insert into student (user_name) values ($ username )";
Mysql_query ("set names gb2312 ");
Mysql_query ($ exec, $ link); // if this user does not exist, insert the data to the database (registered user)
Echo "user registration successful! ";
}
Else
{
Echo "this user name already exists. please select another user name! ";
}
?>
...