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!
-
-
2014 Contacts
Name
Nickname
Gender
Birthday
Phone
Qq
Email
Home
School
Grade
Professional
Company
Duties
Address
Weibo home
Renren Homepage
QQ Space Homepage
Avatar
Brief introduction
-
Copy Code
<?php
Save picture file
@header (' Content-type:text/html;charset=utf-8 ');
Upload image
$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);
Image link Insert database, easy to click and download view, no need to upload the image itself to the database, encoding also decoding,
$_post[' photo ']= "http://localhost/1/c/photos/". $name;
echo " Hello ". $_post[" Name "]."!
";//Return success information, and be your own avatar
}
-
$arr 1= "Name,nickname,gender,birthday,phone,qq,email,home,college,grade,major,company,position,address, Weibolink,renrenlink,qqzonelink,photo,profile ";
Don't think about how to prevent SQL injection, just use Pdo_prepare
$db =new PDO ("Mysql:host=localhost;dbname=test", "Root", "") or Die (Print_r ($db->errorinfo (), true));
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.
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 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.
$s = "?";
for ($j =0; $j <18; $j + +) {
$s. = ",?";
}
$add = "INSERT into BJ ({$arr 1}) VALUES ({$s})";
$q = $stmt = $db->prepare ($add);
This is the local bar. Text processing finished and then put up, looked hard to input, the middle also error many times,
$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
-
<?php
$arr 1= "Name,nickname,gender,birthday,phone,qq,email,home,college,grade,major,company,position,address, Weibolink,renrenlink,qqzonelink,profile ";
$arr 2=explode (",", $arr 1);
echo " ".' $arr 2 '. " ";
for ($i =0; $i <count ($arr 2); $i + +) {
$arr 3[$i]= ' "$_post[\ $arr 2[$i]. ' \']"';
}
echo " ".' $arr 3 '. " ";
echo $arr 3;
$arr 4=implode (",", $arr 3);
' $_post[' name '] ', ' $_post[' nickname '] ', ' $_post[' gender '] ', ' $_post[' birthday '] ', ' $_post[' phone ' ', ' $_post[' QQ ' ] ', ' $_post[' email '] ', ' $_post[' home ',........
echo " ".' $arr 4 '. " ";
Echo $arr 4;
$arr 5= "'". $arr 4. "'";
echo " ".' $arr 5 '. " ";
echo $arr 5;
$db =new PDO ("Mysql:host=localhost;dbname=test", "Root", "");
$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) ");
Echo ' $db: ';
$insert = "INSERT into BJ ({$arr 1}) VALUES ({$arr 4})";
echo " ".' $insert: '. ' ";
$s = "?";
for ($j =0; $j <18; $j + +) {
$s. = ",?";
}
$add = "INSERT into BJ ({$arr 1}) VALUES ($s)";
$stmt = $db->prepare ($add);
$stmt->execute (Array ($arr 4));
?>
$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 ')"
$arr 5
' $_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:
-
Copy Code |