Phpajax registration verification User Name Code

Source: Internet
Author: User
This is a registration program. when the user enters the user name, it will automatically go to the database to check whether the user's user name to be registered has been registered. if it is returned, a prompt is displayed; otherwise, the user can be registered.

This is a registration program. when the user enters the user name, it will automatically go to the database to check whether the user's user name to be registered has been registered. if it is returned, a prompt is displayed; otherwise, the user can be registered.

Conn. php file

  1.  
  2.  
  3. Var xmlhttp
  4. Function showhint (str)
  5. {
  6. If (str. length = 0)
  7. {
  8. Document. getelementbyid ("txthint"). innerhtml = ""
  9. Return
  10. }
  11. Xmlhttp = getxmlhttpobject ()
  12. If (xmlhttp = null)
  13. {
  14. Alert ("browser does not support http request ")
  15. Return
  16. }
  17. Xmlhttp. onreadystatechange = statechanged
  18. Var geturl = "conn. php? Q = "+ str
  19. // Sid is to add a random number to prevent the cache technology from being enabled on the page ·
  20. Geturl = geturl + "& sid =" + math. random ()
  21. Geturl = encodeuri (geturl );
  22. Geturl = encodeuri (geturl );
  23. Xmlhttp. open ("get", geturl, true)
  24. Xmlhttp. send (null)
  25. }
  26. Function statechanged ()
  27. {
  28. If (xmlhttp. readystate = 4 | xmlhttp. readystate = "complete ")
  29. {
  30. Document. getelementbyid ("txthint"). innerhtml = xmlhttp. responsetext
  31. }
  32. }
  33. Function getxmlhttpobject ()
  34. {
  35. Var xmlhttp = null;
  36. Try
  37. {
  38. // Firefox, opera 8.0 +, safari
  39. Xmlhttp = new xmlhttprequest ();
  40. }
  41. Catch (e)
  42. {
  43. // Internet explorer
  44. Try
  45. {
  46. Xmlhttp = new activexobject ("msxml2.xmlhttp ");
  47. }
  48. Catch (e)
  49. {
  50. Xmlhttp = new activexobject ("microsoft. xmlhttp ");
  51. }
  52. }
  53. Return xmlhttp;
  54. }
  55. Script
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. $ Q = $ _ get ["q"];
  63. $ Q = urldecode ($ q );
  64. If (strlen ($ q)> 0)
  65. {
  66. $ Conn = @ mysql_connect ("localhost", "root", "1010") or die ("mysql connection error ");
  67. Mysql_select_db ("xin", $ conn );
  68. Mysql_query ("set names 'utf8 '");
  69. $ SQL = "select username from message where username = '$ Q '";
  70. $ Query = mysql_query ($ SQL );
  71. @ $ Row = mysql_fetch_array ($ query );
  72. If (! Emptyempty ($ row ['username'])
  73. {
  74. $ Response = "registered! ";
  75. } Else
  76. {
  77. $ Response = "Congratulations! Yes! ";
  78. }
  79. Echo $ response;
  80. }
  81. ?>

Database

  1. Drop database if exists 'sin ';
  2. Create database 'sin '/*! 40100 default character set utf8 */;
  3. Use 'sin ';
  4.  
  5. Create table 'message '(
  6. 'Id' int (11) not null auto_increment,
  7. 'Username' varchar (20) default null,
  8. Primary key ('id ')
  9. ) Engine = innodb auto_increment = 2 default charset = utf8;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.