将html表单存储到我的数据库

时间:2017-10-08 06:03:31

标签: php html mysql phpmyadmin

我是新手,我正在研究需要简单三件事的项目。

  1. 创建一个html表单
  2. 从用户
  3. 获取输入
  4. 将表单保存到数据库并由管理员查看。
  5. 此表单将在本地运行。

    基于互联网搜索以及从这个社区读取我已经为registration.html,connection.php,modified.php,listing.php和使用xampp工具编写了代码在phpmyadmin中我为每个条目创建了表。

    这里当我在表单中插入数据并保存时,它不会保存在数据库中。

    这是我使用phpmyadmin phpmyadmin page

    创建的表条目

    我的注册页码

    `

      <html>    
            <head>    
                <title>Registration Form</title>    
            </head>    
            <body>    
                <link href = "registration.css" type = "text/css" rel = "stylesheet" />    
                <h2>Sign Up</h2>    
                <form name = "form1" action="modified.php" method = "post" enctype = "multipart/form-data" >    
                    <div class = "container">    
                        <div class = "form_group">    
                            <label>First Name:</label>    
                            <input type = "text" name = "fname" value = "" required/>    
                        </div>    
                        <div class = "form_group">    
                            <label>Middle Name:</label>    
                            <input type = "text" name = "mname" value = "" required />    
                        </div>    
                        <div class = "form_group">    
                            <label>Last Name:</label>    
                            <input type = "text" name = "lname" value = "" required/>    
                        </div>    
                        <div class = "form_group">    
                            <label>Password:</label>    
                            <input type = "password" name = "pwd" value = "" required/>    
                        </div>
                        <div class = "form_group">
                            <label>Confirm Password:</label>
                            <input type = "confirm password" name = "cnf" value = "" required/>
                        </div>
                        <div class = "form_group">
                            <label>Email:</label>
                            <input type = "Email Address" name = "mail" value = "" required/>
                        </div>
                        <div class = "form_group">
                            <label>Contact No:</label>
                            <input type = "contact number" name = "number" value = "" required/>
                        </div>
                        <div class = "form_group">
                            <label>Gender:</label>
                            <input type = "gender" name = "sex" value = "" required/>
                        <button class="button" id="join"></button>
                    </div>    
                </form>    
            </body>    
        </html>  
    

    ` 我在connection.php文件中编写连接属性。

    `

     <?php  
               $servername = "localhost";  
               $username = "root";  
               $password = "";  
               $dbname = "registration"
               $conn = mysql_connect ($servername , $username , $password, $dbname) or die("unable to connect to host");  
               $sql = mysql_select_db ('test',$conn) or die("unable to connect to database"); 
        ?> 
    

    ` 这是我的listing.php文件

    `

    <?php    
    
    include "connection.php";    
    
    if(isset($_GET['id'])){    
    $sql = "delete from registration where id = '".$_GET['id']."'";    
    $result = mysql_query($sql);    
    }    
    
    $sql = "select * from registration";    
    $result = mysql_query($sql);    
    ?>    
    <html>    
        <body>    
            <table width = "100%" border = "1" cellspacing = "1" cellpadding = "1">    
                <tr>    
                    <td>Id</td>    
                    <td>First Name</td>    
                    <td>Middle Name</td>    
                    <td>Last Name</td>    
                    <td>Password</td>    
                    <td>Confirm Password</td>    
                    <td>Email</td>    
                    <td>Contact No.</td>    
                    <td>Gender</td>    
                    <td colspan = "2">Action</td>    
                </tr>    
            </table>    
        </body>    
    </html>    
    <?php    
    
    while($row = mysql_fetch_object($result)){    
    
    
    ?>  
        <tr>  
            <td>  
                <?php echo $row->id;?>  
            </td>  
            <td>  
                <?php echo $row->fname;?>  
            </td>  
            <td>  
                <?php echo $row->mname;?>  
            </td>  
            <td>  
                <?php echo $row->lname;?>  
            </td>  
            <td>  
                <?php echo $row->pwd;?>  
            </td>  
            <td>  
                <?php echo $row->cnf;?>  
            </td>  
            <td>  
                <?php echo $row->mail;?>  
            </td>  
            <td>  
                <?php echo $row->number;?>  
            </td>  
            <td>  
                <?php echo $row->sex;?>  
            </td>  
            <td> <a href="listing.php?id =     
                <?php echo $row->id;?>" onclick="return confirm('Are You Sure')">Delete    
            </a> | <a href="index.php?id =     
                <?php echo $row->id;?>" onclick="return confirm('Are You Sure')">Edit    
            </a> </td>  
            <tr>  
                <? php } ?>  
    

    `

0 个答案:

没有答案