gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 16:33:37 25 4
gpt4 key购买 nike

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

插入.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>

名称.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>

性别.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)继续按原样进行,一天后,安排一个查询运行,该查询将用行下方的数据填充性别空间,并在上面填充时清空同一行性别

示例

fname fgender

salman -

- male


ramya -


- female

一天后

fname fgender


salman male


ramya female

或者

将一个数据(fname 或 fgender)存储在 session 或临时变量中,当您拥有这两个字段时,然后执行 sql 查询

希望能回答这个问题

关于php - 如何将不同的html页面值存储到数据库的同一行中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53738412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com