1

index.phpプロジェクトで 、class.php、およびの 3 つのファイルを使用していますstyles.css

すべての関数は、class.php ファイルの php クラス内に存在します。

<?php

class Club
{
    //Private Data
    private $HostName;      //typically "localhost"
    private $UserId;
    private $Password;
    private $DBName;
    private $Con;           //MySQL Connection
    //Public Methods
    //Constructor
    public function __construct($host = NULL, $uid = NULL, $pw = NULL, $db = NULL)
    {
        $this->HostName = $host;
        $this->UserID = $uid;
        $this->Password = $pw;
        $this->DBName = $db;

        //Connect to Database
        $this -> Con = mysqli_connect($host, $uid, $pw, $db);
        if(mysgli_connect_errno($this -> Con))
        {
            echo "Failed to connect to MySQL; " . mysqli_connect_error();
        }

    }
    //Destructor
    public function __destruct()
    {
        //Close connection
        mysqli_close($this -> Con);
    }
    public function DisplayMembers()
    {
            }
            function DisplayAbout()
    {
            }
            function DisplayRegistrationForm()
    {
        echo("<h2>Become a Club Member</h2>

        <form name='register' method='post' action=''>
            <table>
                <tbody>
                    <tr>
                        <td width='80px'>
                            <label>First Name: </label>
                        </td>
                        <td width='300'>
                            <input id='firstname' type='text' name='firstname' value='' required/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>Last Name: </label>
                        </td>
                        <td>
                            <input id='lastname' type='text' name='lastname' value='' required/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>Your Email: </label>
                        </td>
                        <td>
                            <input id='email' type='text' name='email' value='' required/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>Gender: </label>
                        </td>
                        <td>
                            <input id='gender' type='radio' name='gender' value='male'>Male<br />
                            <input id='gender' type='radio' name='gender' value='female'>Female
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>Interested in: </label>
                        </td>
                        <td id='check'>
                            <span style='font-weight: bold;'>Check All that Apply:</span><br />
                            <input id='interests' type='checkbox' name='interests[]' value='Pizza Party'>Pizza Party<br />
                            <input id='interests' type='checkbox' name='interests[]' value='Joining Study Groups'>Joining Study Groups<br />
                            <input id='interests' type='checkbox' name='interests[]' value='Visiting Employer Sites'>Visiting Employer Sites<br />
                            <input id='interests' type='checkbox' name='interests[]' value='Participating in Programming Competition'>Participating in Programming Competitions<br />
                            <input id='interests' type='checkbox' name='interests[]' value='Building Games'>Building Games<br />
                            <input id='interests' type='checkbox' name='interests[]' value='Becoming an Officer of the Club'>Becoming an Officer of the Club
                        </td>
                    </tr>
                    <tr>
                        <td colspan='2' style='text-align: center;'>
                            <input id='submit' type='submit' name='submit' value='Sign Up'/>
                        </td>
                    </tr>
                </tbody>
            </table>    
        </form>");
    }
            function ProcessRegistrationForm()
    {
            }
            private function Get_Members_From_DB()
    {
            }
            private function Get_Members_Interests_From_DB($MemberEmail)
    {
            }
            private function Get_Interests_Types_From_DB()
    {
            }
 }
 ?>

ProcessRegistrationFunction()クラス内で使用するために、フォーム部分のアクションセクションに何を入れればよいか、一生わかりません。つまり、基本的にはファイル内の でDisplayRegistrationForm()呼び出され、クラス内でによって処理されます。しかし、私はこれを行う方法を理解できないようです。index.phpdivProcessRegistrationFunction()

4

2 に答える 2

3

フォーム データを index.php 自体に送信し、任意のデータをプロセス関数に送信できます。これを実装する最善の方法は、データを配列として収集するようにフォームを変更することです。

ここmyFormArrayには、フォームに関するすべての情報が保存されます

<input id='firstname' type='text' name='myFormArray[firstname]' value='' required/>

<input id='lastname' type='text' name='myFormArray[lastname]' value='' required/>

この値は、フォームを送信するときに index.php でアクセスできます。

だからあなたのindex.phpで

 if(isset($_POST["submit"]){
    $formData = $_POST["myFormArray"]; // dont forget to sanitize any post data
   //than you can call your class function and pass this data
   $class = new class();
   $class->ProcessRegistrationFunction($formData);
 }

ProcessRegistrationFunction($data) には、すべてのデータが配列形式で含まれるようになります。

それを反復して、個々の値を取得できます

注: クラスには多くの構文エラーがあります..また、このクラスを実装するためのより良い方法があります..クラス内の html コードを常に避ける必要があります..

ディンス

于 2013-04-28T23:47:44.703 に答える
0

タイプを正しく入力しながら、不要なエラーを回避できます

 'if(mysgli_connect_errno($this -> Con))'

そのはず

 'if(mysqli_connect_errno($this -> Con))'
于 2013-12-07T04:58:11.397 に答える