我已经完成了如下表单所示的数据库连接,并插入了代码中所示的值
插入.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条答案
按热度按时间kmbjn2e31#
有两种解决方法:1)保持原样,在一天之后,安排运行一个查询,该查询将在第行下面的gender空间中填充数据,并在上面填充相同的gender行时清空该行
例子
一天后
或者
在会话或临时变量中存储一个数据(fname或fgender),当两个字段都有时,执行sql查询
希望这能回答问题