Xinlin tutorial (IV) _ PHP Tutorial

Source: Internet
Author: User
Xinglin record (4 ). Personal Management: class Address Book: classaddress. php? Session_start (); start sessionif (! Session_is_registered (userregister) | ($ userregister) check for registration, such as userregist personal management:
Class address book: class/address. php
Session_start (); // start session
If (! Session_is_registered ("userregister") | ($ userregister = "") // check whether it is registered. if userregister is not registered or the session is null, register it again.
{
Echo "please register again
";
Exit;
}
?>



Class address book















Include "config. php ";
$ Result = mysql_query ("SELECT * FROM user", $ db );
$ Row = mysql_num_rows ($ result); // Check the number of rows in the result.
For ($ I = 0; $ I <= ($ row-1); $ I ++ ){
$ Name = mysql_result ($ result, $ I, 'name ');
$ Sex = mysql_result ($ result, $ I, 'sex ');
$ Birth = mysql_result ($ result, $ I, 'birth ');
$ Ph = mysql_result ($ result, $ I, 'ph ');
$ Bp = mysql_result ($ result, $ I, 'BP ');
$ Email = mysql_result ($ result, $ I, 'Email ');
$ Oicq = mysql_result ($ result, $ I, 'oicq ');
$ Work = mysql_result ($ result, $ I, 'Work ');
$ Photo = mysql_result ($ result, $ I, 'photo ');
$ Ad = mysql_result ($ result, $ I, 'AD ');
$ Post = mysql_result ($ result, $ I, 'post ');
$ Account = mysql_result ($ result, $ I, 'account ');
$ Face = mysql_result ($ result, $ I, 'face ');
$ Face = 'image/face/icon '. $ face;
Echo"

...................... ○ Class address book ○ ....................

Name: $ name Gender: $ sex Birthday: $ birth
Tel: $ ph Call: $ bp
Email: $ email Oicq: $ oicq
Work unit: $ work Zip code: $ post
Mailing Address: $ ad
Personal photo: $ photo
Personal description: $ account
";
}
?>



Modify personal data: class/modify. php
Session_start (); // start session
If (! Session_is_registered ("userregister") | ($ userregister = "") // check whether it is registered. if userregister is not registered or the session is null, register it again.
{
Echo "please register again
";
Exit;
}
?>



Personal data modification


Include "config. php ";
If ($ submit ){
If (! $ Username |! $ Psw |! $ Psw2 |! $ Name |! $ Ad |! $ Ph |! $ Email) {// check whether it is complete
Echo "Sorry, you must fill in all projects!
"." Refill ";
Exit;
}
$ User = trim ($ username );
$ Psw = trim ($ psw );
$ Psw2 = trim ($ psw2 );
$ Name = trim ($ name );
$ Birth = trim ($ birth );
$ Work = trim ($ work );
$ Ad = trim ($ ad );
$ Post = trim ($ post );
$ Ph = trim ($ ph );
$ Bp = trim ($ bp );
$ Email = trim ($ email );
$ Oicq = trim ($ oicq );
$ Account = strip_tags (trim ($ account); // remove spaces and html tags
$ Signature = strip_tags (trim ($ signature ));
// Check whether the password already exists
If (! $ Psw = $ psw2 ){
Echo "confirm the password and return ";
Exit;
}
// Check the validity of the email
If (! Ereg ('^ [-! # $ % & '* +./0-9 =? A-Z ^ _ 'a-z {|} ~] + '.'@'.'[-! # $ % & '* + \/0-9 =? A-Z ^ _ 'a-z {|} ~] + .'.'[-! # $ % & '* + \./0-9 =? A-Z ^ _ 'a-z {|} ~] + $ ', $ Email) & $ email ){
Echo "email is invalid!
"." Refill
";
Exit ;}
// Write data to the database
$ SQL = "UPDATE user SET user = '$ user', psw =' $ psw', name = '$ name', sex =' $ sex ', birth = '$ birth', work = '$ work', ad =' $ ad', post = '$ post', ph =' $ ph ', bp = '$ bp', email = '$ email', oicq = '$ oicq', account = '$ account', signature =' $ signature ', face = '$ face' where user =' $ userregister '";
$ Result = mysql_query ($ SQL, $ db );
Mysql_close ($ db );
// Send a congratulation email
$ Subject = "Congratulations, you have successfully modified your personal information". $ sitename ."! "; // Topic
$ Message = $ name. ", hello:
Congratulations! you have modified your personal information! Your username is ". $ username." and the password is ". $ psw ."
Log on to $ sitename "; // mail content
$ Headers. = "Content-Type: text/html; charset = gb2312n"; // Mime type
Mail ($ email, $ subject, $ message, $ headers );
Echo "Congratulations! A welcome letter has been sent to your mailbox. check it carefully. ";
Exit;
}
$ Result = mysql_query ("SELECT * FROM user where user = '$ userregister'", $ db );
$ Psw = mysql_result ($ result, 0, "psw ");
$ Name = mysql_result ($ result, 0, "name"); // read personal registration information
$ Sex = mysql_result ($ result, 0, "sex ");
$ Birth = mysql_result ($ result, 0, "birth ");
$ Work = mysql_result ($ result, 0, "work ");
$ Ad = mysql_result ($ result, 0, "ad ");
$ Post = mysql_result ($ result, 0, "post ");
$ Ph = mysql_result ($ result, 0, "ph ");
$ Bp = mysql_result ($ result, 0, "bp ");
$ Email = mysql_result ($ result, 0, "email ");
$ Oicq = mysql_result ($ result, 0, "oicq ");
$ Photo = mysql_result ($ result, 0, "photo ");
$ Account = mysql_result ($ result, 0, "account ");
$ Signature = mysql_result ($ result, 0, "signature ");
$ Face = mysql_result ($ result, 0, "face ");
Mysql_close ($ db );
?>













Personal data modification

Note that there are no spaces. the project with * is required.







Upload Photo: class/uploadphoto. php
Session_start (); // start session
If (! Session_is_registered ("userregister") | ($ userregister = "") // check whether it is registered. if userregister is not registered or the session is null, register it again.
{
Echo "please register again
";
Exit;
}
?>



Upload photo


Include "../config. php ";
If ($ upload ){
If ($ picurl = "none "){
Echo "you have not uploaded any files .";
Exit;
}
$ V = opendir ("image ");
If ($ v = 0)
{Mkdir ("image"); // if the directory does not exist, create
$ V = opendir ("image"); // Get the directory handle
}
$ Up = copy ("$ picurl", "image/$ picurl_name ");
If ($ up = 1)
{
// Initialize the written content
$ Result = mysql_query ("SELECT * FROM user where user = '$ userregister'", $ db); // query previous photo information
$ Photo = mysql_result ($ result, 0, 'photo ');
$ Photo = str_replace ("'", "'", $ photo); // replace''
$ Photo = $ photo. "View photo |"; // add this content.
Mysql_query ("UPDATE user SET photo = '$ photo' where user = '$ userregister'", $ db); // write
Mysql_close ($ db );
Echo "file uploaded successfully!
";
Echo "File name: $ picurl_name file size: $ picurl_size byte file type: $ picurl_type
";
}
Else
{Echo "file Upload failed."; exit ;}
Unlink ($ picurl); // delete a file from a temporary folder $ picurl
Closedir ($ v); // Close the directory handle
Exit;
}
?>









Upload photo







Workshop class address Book: class/address. php? Session_start (); // start session if (! Session_is_registered (userregister) | ($ userregister =) // check whether the account is registered, such as userregist...

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.