Xoops module development Quick Start Chinese translation (4)

Source: Internet
Author: User
Since I have been studying the xoops module for the past two days, I found this good module development quick start.
After reading it, I came to the development module with great interest, but encountered some problems during the development process.
I think it's too fast to learn. Therefore, the translation is here.
====================
Author: surance Yin
Email: Suranceyin@yahoo.com.cn
Home: http://www.fltek.com.cn
========================

Use Forms and databases

Now we areNdex. phpCreate a form

<? PHP
// Tutorial
// Created by kaotik
Require ('HTTP: // www.cnblogs.com/mainfile.php ');
Require (xoops_root_path. '/header. php ');
?>
<Form name = "tutorial_form" method = "Post" Action = "index. php">
<Table width = "400" border = "0">
<Tr>
<TD align = "right"> name </TD>
<TD> <input type = "text" name = "name"> </TD>
</Tr> <tr>
<TD align = "right"> address </TD>
<TD> <input type = "text" name =" Address "> </TD>
</Tr> <tr>
<TD align = "right"> telephone </TD>
<TD> <input type = "text" name = "tel"> </TD>
</Tr> <tr>
<TD align = "right"> email </TD>
<TD> <input type = "text" name = "email"> </TD>
</Tr> <tr>
<TD> & nbsp; </TD>
<TD> <input type = "Submit" name = "Submit" value = "Submit"> </TD>
</Tr>
</Table>
</Form>
<? PHP
Require (xoops_root_path. '/footer. php ');
?>

click tutorial , you can see a file containing name, address, telephone and email , submit button form . Click " submit " will return to index. php however, no database operations are performed. Add the following Code :

// tutorial
// created by kaotik
require ('HTTP: // www.cnblogs.com/mainfile.php');
require (xoops_root_path. '/header. PHP ');

If (isset ($ _ post ['submit ']) {
echo 'My name is :'. $ _ post ['name'];
}
?>


Now I only show some of the above Code, which looks a little less..

Now, if you clickSubmitYou will see"My name is :"Your name is behind.

Here we have explainedPHP.

<? PHP
// Tutorial
// Created by kaotik
Require ('HTTP: // www.cnblogs.com/mainfile.php ');
Require (xoops_root_path. '/header. php ');

If (isset ($ _ post ['submit ']) {
If (empty ($ _ post ['name']) {
Echo 'Please fill in a Name ';
} Else {
Echo 'My name is: '. $ _ post ['name'];
}
}
?>

If the user name is not specified, an error is returned.

Here we have explainedPHP.

Store data to the database

Let's continue. Now we need to insert the data into the database.

<? PHP
// Tutorial
// Created by kaotik
Require ('HTTP: // www.cnblogs.com/mainfile.php ');
Require (xoops_root_path. '/header. php ');

If (isset ($ _ post ['submit ']) {
If (empty ($ _ post ['name']) {
Echo 'Please fill in a Name ';
} Else {
$ Name = $ _ post ['name'];
$ Address = $ _ post ['address'];
$ Tel = $ _ post ['tel'];
$ Email = $ _ post ['email '];
$ Query = "insert ". $ xoopsdb-> prefix ("tutorial_myform "). "(name, address, telephone, email) values ('$ name',' $ address', '$ Tel', '$ email ')";
$ Res = $ xoopsdb-> query ($ query );
If (! $ Res ){
Echo "error: $ query ";
} Else {
Echo "data was correctly inserted into DB! ";
}
}
}
?>

Before the new Code4Returns the form data to the variable. In this way, you can easily understand the content of the Code.The following $ QueryUsed in $ Xoopsdb:

$ Res = $ xoopsdb-> query ($ query );

The following line:

If (! $ Res)


is used to check whether an exception occurs during database insertion. If yes, print " data was correctly inserted into DB! ". I will explain the following in detail .

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.