如何将不同的html页面值存储到数据库的同一行中?

时间:2018-12-12 07:56:05

标签: php html mysql forms

我已经完成了如下所示的数据库连接,并插入了代码中所示的值

insert.php

<html>
    <body>
        <?php
            $conn=new mysqli('localhost','root','');
            if($conn->connect_error){
               die("connection failed" .$conn->connect_error);
            }
            echo "DB connected successfully";
            mysqli_select_db($conn,"namesql_db");
            echo "\n DB is selected as Test successfully";
            $sql="INSERT INTO namesql_table(fname,fgender) VALUES('$_POST[fname]','$_POST[fgender]')";

            if($conn->query($sql)==TRUE){
               echo "New record created successfully";
            } 
            else {
               echo "Error:" .$sql."<br>" .$conn->error;
            }               
            mysqli_close($conn);
        ?>
    </body>
</html>

name.html

<html>
    <body>
        <head>
            <title>DIABETES RISK SCORE SYSTEM</title>
        </head>
        <body bgcolor="lightgreen" text="black" style="font-size:18pt  font-family:Garamond">
            <center>
                <h2>DIABETES RISK SCORE SYSTEM</h2>
            </center>
            <form action="insert.php" method="post">
                <br/><br/><br/>Enter your name:<input type="text" name="fname"pattern="  [A-Za-z]+" required /><br> <br>
                <input type="submit"/>
            </form>
            <br/><br/><br/><br/><br/>
            <a href="taketest.php" class="btn">BACK</a>
            <a href="Gender.html" class="btn">NEXT</a>
    </body>
</html>

Gender.html

<html>
    <body>
        <head>
            <title>DIABETES RISK SCORE SYSTEM</title>
        </head>
        <body bgcolor="lightgreen" text="black" style="font-size:18pt;font-family:Garamond">
            <center>
                <h2>DIABETES RISK SCORE SYSTEM</h2>
            </center>
            <form action="insert.php" method="post">
                <br/><br/><br/>Enter your Gender:<br/><br/><br/><input type="radio"    name="fgender"value="female" checked />Female<br>
                <input type=radio name="fgender" value=male>Male</td><br> <br>
                <input type="submit"/>
            </form>
            <img src="mf.png" align="right" width="300" height="300"><br/><br/><br/> 
            <br/><br/><br/><br/><br/>
            <a href="name.php" class="btn">BACK</a>
            <a href="Age.html" class="btn">NEXT</a>
    </body>
</html>

连接数据库后,我就创建了表并插入了值,使其以表格形式存储

fname  fgender
ramya   -
   -   female

但是实际上我想将姓名和性别本身存储在

fname  fgender
ramya   female

1 个答案:

答案 0 :(得分:0)

两种解决方法: 1)保持原样,然后安排一天的查询以使用以下行的数据填充性别空间,并在填充了

以上的空白行时清空该行

示例

fname fgender

salman   -

-      male


ramya    -


-      female

一天之后

fname fgender


salman male


ramya female

OR

在会话或临时变量中存储一个数据(fname或fgender),当您同时拥有两个字段时,执行sql查询

希望能回答这个问题