PHP Simple implementation of Address Book collection, my first PHP, suitable for beginners

Source: Internet
Author: User
Tags how to prevent sql injection learn php stmt
Origin in order to organize the Address book, the original use is a file survey, now learn PHP, try it yourself.
The program is short and concise, suitable for learning.
There are two files, bj.html used to display and collect form information. bj.php is used to process data and feedback results.
The highlight is that you can upload your avatar.
In fact, there is a test.php, for debugging, intermediate processing. Look at this from the beginning.
The comment is very detailed, the label, function does not right-click Search.
Because the web directory is a lot, put in the./1/folder, set a bookmark in Firefox for easy access
When you deploy it, bj.html change to index.php.

Originally wanted to build a IPv6 free Internet application platform (now know is the OAuth open platform), began to learn php,php is the simplest, but also learned a year before the first program, cautious into!






  1. 2014 Contacts

  2. Name

  3. Nickname

  4. Gender

  5. Birthday


  6. Phone

  7. Qq

  8. Email

  9. Home



  10. School

  11. Grade

  12. Professional

  13. Company

  14. Duties

  15. Address

  16. Weibo home

  17. Renren Homepage

  18. QQ Space Homepage


  19. Avatar


  20. Brief introduction







Copy Code


  1. <?php

  2. Save picture file

  3. @header (' Content-type:text/html;charset=utf-8 ');


  4. Upload image

  5. $filepath =$_files["Photo" ["Tmp_name"];

  6. $filename =explode ('. ', $_files[' photo ' [' name ']);

  7. $filename [0]=$_post[' name '];

  8. $name =implode ('. ', $filename);


  9. $uploaded = "./photos/". $name;

  10. if (file_exists ($filepath)) {

  11. Move_uploaded_file ($filepath, $uploaded);

  12. Image link Insert database, easy to click and download view, no need to upload the image itself to the database, encoding also decoding,

  13. $_post[' photo ']= "http://localhost/1/c/photos/". $name;

  14. echo "
    Hello
    ". $_post[" Name "]."!

    ";//Return success information, and be your own avatar


  15. }



  16. $arr 1= "Name,nickname,gender,birthday,phone,qq,email,home,college,grade,major,company,position,address, Weibolink,renrenlink,qqzonelink,photo,profile ";


  17. Don't think about how to prevent SQL injection, just use Pdo_prepare


  18. $db =new PDO ("Mysql:host=localhost;dbname=test", "Root", "") or Die (Print_r ($db->errorinfo (), true));


  19. Here is the code to try, because MySQL garbled, try this, and finally not. Had to change the mariadb, the whole world is pure. can be deleted for reference.

  20. Mysqli_query ("Set names ' UTF8 '");

  21. Mysqli_query ("Set Character_set_client=utf8");

  22. Mysqli_query ("Set Character_set_results=utf8");


  23. This is the only automatic processing of the script, initially think of the operation is put here in fact, this is a static variable, the local processing and then put it up again, because it is simple, realized, the local '? '. '? ', ' The results of the *18 can be posted.

  24. $s = "?";

  25. for ($j =0; $j <18; $j + +) {

  26. $s. = ",?";

  27. }


  28. $add = "INSERT into BJ ({$arr 1}) VALUES ({$s})";

  29. $q = $stmt = $db->prepare ($add);


  30. This is the local bar. Text processing finished and then put up, looked hard to input, the middle also error many times,


  31. $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"]);

  32. $stmt->execute ($array);


  33. ?>


Copy Code





  1. <?php



  2. $arr 1= "Name,nickname,gender,birthday,phone,qq,email,home,college,grade,major,company,position,address, Weibolink,renrenlink,qqzonelink,profile ";


  3. $arr 2=explode (",", $arr 1);

  4. echo "
    ".' $arr 2 '. "
    ";


  5. for ($i =0; $i <count ($arr 2); $i + +) {

  6. $arr 3[$i]= ' "$_post[\ $arr 2[$i]. ' \']"';

  7. }

  8. echo "
    ".' $arr 3 '. "
    ";

  9. echo $arr 3;

  10. $arr 4=implode (",", $arr 3);

  11. ' $_post[' name '] ', ' $_post[' nickname '] ', ' $_post[' gender '] ', ' $_post[' birthday '] ', ' $_post[' phone ' ', ' $_post[' QQ ' ] ', ' $_post[' email '] ', ' $_post[' home ',........

  12. echo "
    ".' $arr 4 '. "
    ";

  13. Echo $arr 4;

  14. $arr 5= "'". $arr 4. "'";

  15. echo "
    ".' $arr 5 '. "
    ";

  16. echo $arr 5;


  17. $db =new PDO ("Mysql:host=localhost;dbname=test", "Root", "");

  18. $r 1= $db->exec ("INSERT INTO BJ" (Name,nickname,gender,birthday,phone,qq,email,home,college,grade,major,company , Position,address,weibolink,renrenlink,qqzonelink,profile) VALUES ($arr 3) ");

  19. Echo ' $db: ';


  20. $insert = "INSERT into BJ ({$arr 1}) VALUES ({$arr 4})";

  21. echo "
    ".' $insert: '. '
    ";



  22. $s = "?";

  23. for ($j =0; $j <18; $j + +) {

  24. $s. = ",?";

  25. }


  26. $add = "INSERT into BJ ({$arr 1}) VALUES ($s)";

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

  28. $stmt->execute (Array ($arr 4));


  29. ?>


  30. $sql = "INSERT INTO ' tbl ' values ('". $_post[' name ']. " ', ' " . $_post[' title ']. " ' )";

  31. $sql = "INSERT INTO ' tbl ' values (' {$_post[' name '} ', ' {$_post[' title ']} ')"


  32. ' INSERT into '. $table. ' ('. $cols. ') VALUES ('. $vals. ') ';


  33. $stmt = $dbh->prepare ("select * from REGISTRY where name =?");

  34. if ($stmt->execute (Array ($_get[' name '))) {

  35. while ($row = $stmt->fetch ()) {

  36. Print_r ($row);

  37. }

  38. }


  39. $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[' profile '} ");


  40. "$_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[' profile ')"

  41. $arr 5

  42. ' $_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[' profile ' "' $db:

  43. $insert:


Copy Code
  • 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.