当前位置:Gxlcms > PHP教程 > php简单实现通讯录采集,我的第一个php,适合新手

php简单实现通讯录采集,我的第一个php,适合新手

时间:2021-07-01 10:21:17 帮助过:27人阅读

起源于要整理通讯录,原先用的是文件调查,现在学了php,就自己试一下.
程序短小精悍,适于学习.
有两个文件,bj.html用于显示和采集表单信息.bj.php用于处理数据和反馈结果.
突出之处在于可以上传阅览头像.
其实还有一个test.php,用于调试,中间处理.从这个开始先看.
注释很详细,标签,函数不会的话右键搜索.
因为web目录很多,放在./1/文件夹下,在火狐设一个书签方便访问
部署时吧bj.html改成index.php

原先想着搭建一个ipv6免费上网的应用平台(现在知道了是oauth开放平台),就开始学php,php是最简单的了,可也学了一年才有第一个程序,慎入!






  1. 2014年通讯录

  2. 姓名

  3. 小名

  4. 性别

  5. 生日


  6. 电话

  7. qq

  8. email

  9. 老家



  10. 学校

  11. 年级

  12. 专业

  13. 公司

  14. 职务

  15. 地址

  16. 微博主页

  17. 人人主页

  18. qq空间主页


  19. 头像


  20. 简介








  1. <?php

  2. //保存图片文件

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


  4. //上传图片

  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. //图片链接插入数据库,方便点击和下载查看,没必要吧图片本身上传到数据库,编码还解码,

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

  14. echo "
    hello,
    ".$_POST["name"]."!
    <img src='".$uploaded."'

    ";//返回成功信息,而且是自己的头像


  15. }



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


  17. //没想好怎么防止sql注入,就用pdo_prepare


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


  19. //下面是尝试的代码,因为mysql乱码,试了下这个,最终不行.只好换了mariadb,整个世界就清净了.可以删掉,用以参考.

  20. mysqli_query("set names ’utf8’ ");

  21. mysqli_query("set character_set_client=utf8");

  22. mysqli_query("set character_set_results=utf8");


  23. //这是唯一一个自动处理脚本,最初想着把运算都放在这里其实这个是变量静态的,被当地处理完毕再放上来未尝不可,因为简单,实现了,本地把 '?'.'?,'*18 的结果贴出来就可以了.

  24. $s="?";

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

  26. $s.=",?";

  27. }


  28. $add="insert into bj ({$arr1}) values ({$s})";

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


  30. //这个就是本地吧文本处理完毕再放上来,看着很难输入,中间也出错了很多次,


  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. ?>






  1. <?php



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


  3. $arr2=explode(",",$arr1);

  4. echo "
    ".'$arr2'."
    ";


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

  6. $arr3[$i]='"$_POST[\''.$arr2[$i].'\']"';

  7. }

  8. echo "
    ".'$arr3'."
    ";

  9. echo $arr3;

  10. $arr4=implode(",",$arr3);

  11. //'$_POST['name']','$_POST['nickname']','$_POST['gender']','$_POST['birthday']','$_POST['phone']','$_POST['qq']','$_POST['email']','$_POST['home']',........

  12. echo "
    ".'$arr4'."
    ";

  13. echo $arr4;

  14. $arr5="'".$arr4."'";

  15. echo "
    ".'$arr5'."
    ";

  16. echo $arr5;


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

  18. //$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)");

  19. echo '$db:';


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

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



  22. $s="?";

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

  24. $s.=",?";

  25. }


  26. $add="insert into bj ({$arr1}) values ($s)";

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

  28. $stmt->execute(array($arr4));


  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. $arr5

  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:


人气教程排行