Heim  >  Artikel  >  Backend-Entwicklung  >  php简单实现通讯录采集,我的第一个php,适合新手

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

PHP中文网
PHP中文网Original
2016-07-25 08:48:261266Durchsuche
起源于要整理通讯录,原先用的是文件调查,现在学了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. //保存图片文件

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


  3. //上传图片

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

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

  13. echo "
    hello,
    ".$_POST["name"]."!

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


  14. }



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


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


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


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

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

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

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


  22. //这是唯一一个自动处理脚本,最初想着把运算都放在这里其实这个是变量静态的,被当地处理完毕再放上来未尝不可,因为简单,实现了,本地把 '?'.'?,'*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. //这个就是本地吧文本处理完毕再放上来,看着很难输入,中间也出错了很多次,


  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['college']}","{$_POST['grade']}","{$_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['college']","$_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['college']","$_POST['grade']","$_POST['major']","$_POST['company']","$_POST['position']","$_POST['address']","$_POST['weibolink']","$_POST['renrenlink']","$_POST['qqzonelink']","$_POST['profile']"'$db:

  42. $insert:


复制代码





Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:PHP memcache 环形队列 Nächster Artikel:DNSPOD API 域名解析示例