Php implements address book collection. My first php is suitable for beginners.

Source: Internet
Author: User
Tags how to prevent sql injection
Php implements address book collection. My first php is suitable for beginners.
It originated from sorting out the address book. I used file surveys. now I have learned php and I will try it myself.
The program is short and concise and suitable for learning.
There are two files. bj.html is used to display and collect form information. bj. php is used to process data and feedback results.
The highlight is that you can upload and view your avatar.
In fact, there is another test. php for debugging and intermediate processing. let's take a look at it from here.
The comment is very detailed. if the tag or function does not, right-click to search.
Because there are many web directories, put them in the./1/folder, and set a bookmark on Firefox for easy access
Change bj.html to index. php during deployment.

I used to build an ipv6 free Internet application platform (now I know it is the oauth open platform), and I started to learn php, which is the simplest, you can also learn the first program in a year, so be careful!






  1. 2014 address book
  2. Name

  3. Nickname

  4. Gender

  5. Birthday


  6. Phone Number

  7. Qq

  8. Email

  9. Home



  10. Schools

  11. Grade

  12. Professional

  13. Company

  14. Title

  15. Address

  16. Weibo homepage

  17. Renren homepage

  18. QQ space Homepage


  19. Avatar


  20. Introduction








  1. // Save the image file

  2. @ Header ('content-type: text/html; charset = UTF-8 ');


  3. // Upload an image

  4. $ Filepath = $ _ FILES ["photo"] ["tmp_name"];

  5. $ Filename = explode ('.', $ _ FILES ['photo'] ['name']);

  6. $ Filename [0] =$ _ POST ['name'];

  7. $ Name = implode ('.', $ filename );


  8. $ Uploaded = "./photos/". $ name;

  9. If (file_exists ($ filepath )){

  10. Move_uploaded_file ($ filepath, $ uploaded );

  11. // Insert the image link to the database for easy clicking and downloading. it is unnecessary to upload the image to the database and decode it,

  12. $ _ POST ['photo'] = "http: // localhost/1/c/photos/". $ name;

  13. Echo"
    Hello,
    ". $ _ POST [" name "]."!

    "; // Return the success message, which is your profile picture.


  14. }



  15. $ Arr1 = "name, nickname, gender, birthday, phone, qq, email, home, college, grade, major, company, position, address, weibolink, renrenlink, qqzonelink, photo, profile ";


  16. // Use pdo_prepare if you have no idea how to prevent SQL injection.


  17. $ Db = new PDO ("mysql: host = localhost; dbname = test", "root", "") or die (print_r ($ db-> errorInfo (), true ));


  18. // Below is the code to be tried. because mysql is garbled, I tried this and eventually it won't work. I had to change mariadb and the whole world would be clean. I can delete it for reference.

  19. Mysqli_query ("set names 'utf8 '");

  20. Mysqli_query ("set character_set_client = utf8 ");

  21. Mysqli_query ("set character_set_results = utf8 ");


  22. // This is the only automatic processing script. it was originally intended to put all the operations here. In fact, this variable is static and can't be put up after local processing, because it is simple and implemented, locally place '? '.'?, You can paste the result of '* 18.

  23. $ S = "? ";

  24. For ($ j = 0; $ j <18; $ j ++ ){

  25. $ S. = ",? ";

  26. }


  27. $ Add = "insert into bj ({$ arr1}) values ({$ s })";

  28. $ Q = $ stmt = $ db-> prepare ($ add );


  29. // This is where the local bar text is processed and then put up. it looks very difficult to input, and there are many errors in the middle,


  30. $ Array = array ($ _ POST ["name"], $ _ POST ["nickname"], $ _ POST ["gender"], $ _ POST ["birthday"], $ _ POST ["phone"], $ _ POST ["qq"], $ _ POST ["email"], $ _ POST ["home"], $ _ POST ["college"], $ _ POST ["grade"], $ _ POST ["major"], $ _ POST ["company"], $ _ POST ["position"], $ _ POST ["address"], $ _ POST ["weibolink"], $ _ POST ["renrenlink"], $ _ POST ["qqzonelink"], $ _ POST ["photo"], $ _ POST ["profile"]);

  31. $ Stmt-> execute ($ array );


  32. ?>








  1. $ Arr1 = "name, nickname, gender, birthday, phone, qq, email, home, college, grade, major, company, position, address, weibolink, renrenlink, qqzonelink, profile ";


  2. $ Arr2 = explode (",", $ arr1 );

  3. Echo"
    ". '$ Arr2 '."
    ";


  4. For ($ I = 0; $ I

  5. $ Arr3 [$ I] = '"$ _ POST [\'. $ arr2 [$ I]. '\']" ';

  6. }

  7. Echo"
    ". '$ Arr3 '."
    ";

  8. Echo $ arr3;

  9. $ Arr4 = implode (",", $ arr3 );

  10. // '$ _ POST ['name']', '$ _ POST ['nickname']', '$ _ POST ['gender']', '$ _ POST ['birthday']', '$ _ POST ['phone']', '$ _ POST ['QQ']', '$ _ POST ['email'] ',' $ _ POST ['home'] ',...

  11. Echo"
    ". '$ Arr4 '."
    ";

  12. Echo $ arr4;

  13. $ Arr5 = "'". $ arr4 ."'";

  14. Echo"
    ". '$ Arr5 '."
    ";

  15. Echo $ arr5;


  16. $ Db = new PDO ("mysql: host = localhost; dbname = test", "root ","");

  17. // $ R1 = $ db-> exec ("insert into bj (name, nickname, gender, birthday, phone, qq, email, home, college, grade, major, company, position, address, weibolink, renrenlink, qqzonelink, profile) values ($ arr3 )");

  18. Echo '$ db :';


  19. $ Insert = "insert into bj ({$ arr1}) values ({$ arr4 })";

  20. Echo"
    ". '$ Insert :'."
    ";



  21. $ S = "? ";

  22. For ($ j = 0; $ j <18; $ j ++ ){

  23. $ S. = ",? ";

  24. }


  25. $ Add = "insert into bj ({$ arr1}) values ($ s )";

  26. $ Stmt = $ db-> prepare ($ add );

  27. $ Stmt-> execute (array ($ arr4 ));


  28. ?>


  29. $ SQL = "insert into 'tbl' values ('". $ _ POST ['name']. "','". $ _ POST ['title']. "')";

  30. $ SQL = "insert into 'tbl' values ('{$ _ POST ['name']}', '{$ _ POST ['title']}')"


  31. 'Insert INTO '. $ table.' ('. $ cols.') VALUES ('. $ vals .')');


  32. $ Stmt = $ dbh-> prepare ("SELECT * from registry where name =? ");

  33. If ($ stmt-> execute (array ($ _ GET ['name']) {

  34. While ($ row = $ stmt-> fetch ()){

  35. Print_r ($ row );

  36. }

  37. }


  38. $ Array = ("{$ _ POST ['name']}", "{$ _ POST ['nickname']}", "{$ _ POST ['gender']}", "{$ _ POST ['birthday']}", "{$ _ POST ['phone']}", "{$ _ POST ['QQ']}", "{$ _ POST ['email ']}", "{$ _ POST ['home']}", "{$ _ POST ['mount']}", "{$ _ POST ['Grad']}", "{$ _ POST ['major']}", "{$ _ POST ['Company']}", "{$ _ POST ['position']}", "{$ _ POST ['address']}", "{$ _ POST ['weibolink']}", "{$ _ POST ['renrenlink']}", "{$ _ POST ['qqzonelink ']}", "{$ _ POST ['Profile ']}");


  39. "$ _ POST ['name']", "$ _ POST ['nickname']", "$ _ POST ['gender']", "$ _ POST ['birthday']", "$ _ POST ['phone']", "$ _ POST ['QQ']", "$ _ POST ['email ']", "$ _ POST ['home']", "$ _ POST ['mount']", "$ _ POST ['grade ']", "$ _ POST ['major']", "$ _ POST ['Company']", "$ _ POST ['position']", "$ _ POST ['address']", "$ _ POST ['weibolink']", "$ _ POST ['renrenlink']", "$ _ POST ['qqzonelink ']", "$ _ POST ['Profile']"

  40. $ Arr5

  41. '"$ _ POST ['name']", "$ _ POST ['nickname']", "$ _ POST ['gender']", "$ _ POST ['birthday']", "$ _ POST ['phone']", "$ _ POST ['QQ']", "$ _ POST ['email ']", "$ _ POST ['home']", "$ _ POST ['mount']", "$ _ POST ['grade ']", "$ _ POST ['major']", "$ _ POST ['Company']", "$ _ POST ['position']", "$ _ POST ['address']", "$ _ POST ['weibolink']", "$ _ POST ['renrenlink']", "$ _ POST ['qqzonelink ']", "$ _ POST ['Profile']" '$ db:

  42. $ Insert:


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.