如何使用php显示数据库中的得分列?

时间:2018-11-28 06:29:08

标签: php html

我已经按照以下格式编写了连接数据库的代码

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(age,fwaist) VALUES('$_POST[age]','$_POST[fwaist]')";

            if($conn->query($sql)===TRUE){

                echo "New record created successfully";

            } else {

                echo "Error:" .$sql."<br>" .$conn->error;

            }

            mysqli_close($conn);

        ?>
    </body>
</html>

我已经像这样写了年龄和腰围的代码:

</head>
<body bgcolor="lightyellow" text="black" style="font-size:18pt; font-family:Garamond"><center>
<h2>DIABETES RISK SCORE SYSTEM</h2></center>
<form action="insert.php" method="post">
<label for="age">Enter your Age: </label>
<select name="age">
  <option value="">--select the age--</option>
  <option value="21-34">21-34</option>
  <option value="35-49">35-49</option>
  <option value="50-80">50-80</option> 
</select>


<p></p>

<script>
  var select = document.querySelector('select');
  var para = document.querySelector('p');
  select.onchange = setage;
  function setage() {
    var choice = select.value;
     if(choice === "21-34") {
      para.textContent = 'The score is 0';
    } else if(choice === "35-49") {
      para.textContent = 'The score is 22';
    } else if(choice === "50-80") {
      para.textContent = 'The score is 34';
    } else {
      para.textContent = '';
    }
  }
</script>
<br/><br/><img src="age1.jpg" align="right" width="300" height="300">
<input type="submit"/>
</form>
<a href="Gender.php" class="btn">BACK</a>

<a href="waist.php" class="btn">NEXT</a>

在使用此代码开发UI时获得分数。例如,如果我单击21-34岁,则获得分数为0。但是在数据库中,仅获得类别,因为21-34未获得得分。有人可以告诉我...

预先感谢

0 个答案:

没有答案