It originated from the need to organize the address book. I originally used file investigation. Now that I have learned PHP, I will try it myself. The program is short and concise, suitable for learning. There are two files, bj.html is used for display and collection Form information.bj.php is used to process data and feedback results. The highlight is that you can upload reading avatars. In fact, there is also a test.php for debugging and intermediate processing. Let’s start with this one. The comments are very detailed , tags, functions, right-click to search. Because there are many web directories, put them under the ./1/ folder, and set a bookmark in Firefox for easy access When deploying, change bj.html to index.php
Originally thought To build an IPv6 free Internet application platform (now I know it is an oauth open platform), I started to learn PHP. PHP is the simplest, but it took me a year to learn the first program, so be careful!
2014 Address Book
Name
-
nickname
-
Gender
-
Birthday
Phone
-
qq
Hometown
-
- School
Grade Major
- Company
Position Address
- Weibo homepage
- Renren homepage
- QQ space homepage
-
avatar
-
Introduction
-
- Copy code
//Save image file @header('Content-type: text/html;charset=UTF-8');-
- //Upload pictures
$filepath=$_FILES["photo"]["tmp_name"]; $filename=explode('.',$_FILES['photo'][ 'name']); $filename[0]=$_POST['name']; $name=implode('.',$filename);- $uploaded="./photos/".$name;
if(file_exists($filepath)){ move_uploaded_file($filepath,$uploaded); //Insert picture link into database, It is convenient to click and download for viewing. There is no need to upload the image itself to the database, encode and decode it, $_POST['photo']="http://localhost/1/c/photos/".$name;-
echo "- hello,
".$_POST["name"]."! - ";//Return success information, and it is your own avatar
- }
- $arr1="name,nickname,gender,birthday,phone, qq,email,home,college,grade ,major,company,position,address,weibolink,renrenlink,qqzonelink,photo,profile";
- //I didn’t think about how to prevent sql injection, so I used pdo_prepare
$db=new PDO("mysql:host=localhost;dbname=test","root","") or die(print_r($db->errorInfo(),true));
//The following is the tried code, because mysql is garbled, I tried this, but it didn’t work in the end. I had to change mariadb, and the whole world was clean. You can delete it for reference.
mysqli_query( "set names 'utf8' ");
mysqli_query("set character_set_client=utf8");
mysqli_query("set character_set_results=utf8");
//This is The only automatic processing script, I originally thought of putting all the operations here. In fact, this variable is static. It is not a bad idea to put it up after being processed locally. Because it is simple, it is implemented. '?'.'?,'*18 Just post the results.
$s="?";
for($j=0;$j<18;$j++){ $s.=",? "; }
$add="insert into bj ({$arr1}) values ({$s})"; $q=$stmt=$db ->prepare($add);
//This is the local bar. After the text is processed, it is put up. It looks difficult to input, and there are many mistakes in the middle.
-
$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"]);
$stmt->execute($array);
?>
-
Copy code
-
-
- $arr1="name,nickname,gender,birthday,phone,qq,email,home,college,grade,major,company,position,address,weibolink,renrenlink,qqzonelink,profile ";
- $arr2=explode(",",$arr1);
echo " ".'$arr2'." ";
for($i=0;$i- $arr3[$i]='"$_POST[''.$arr2[$i].''] "';
- }
echo " ".'$arr3'." ";- echo $arr3;
- $arr4=implode(",",$arr3) ;
- //'$_POST['name']','$_POST['nickname']','$_POST['gender']','$_POST['birthday']','$_POST ['phone']','$_POST['qq']','$_POST['email']','$_POST['home']',.....
echo " ".'$arr4'." ";- echo $arr4;
- $arr5="'".$arr4."'";
echo " ".'$ arr5'." ";- echo $arr5;
- $db=new PDO("mysql:host=localhost;dbname=test","root","");
- //$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)");
-
echo '$db:';
-
🎜
$insert="insert into bj({$arr1}) values ({$arr4})";
echo " ".'$insert:'." ";
$s="?";
for($j=0;$j<18;$j++){ $s.=",?"; }
$add="insert into bj ({$arr1}) values ($s)"; $stmt=$db->prepare($add);
$stmt->execute(array($arr4));
?>
$sql = " insert into `tbl` values(' " . $_POST['name'] . " ', ' " . $_POST['title'] . " ' )";
$sql = " insert into `tbl` values('{$_POST['name']}', '{$_POST['title']}')"
'INSERT INTO '.$table.' ('.$cols.') VALUES ('.$vals.')');
$stmt = $dbh->prepare("SELECT * FROM REGISTRY where name = ?");
if ($stmt->execute(array($_GET['name']))) {
while ($row = $stmt->fetch()) {
print_r($row);
}
}
$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']}");
"$_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']"
$arr5
'"$_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:
$insert:
复制代码
|