enter image description here我想一次将多个文本框值插入到表中的单个列中
应该有名字,名字前面有输入学生年龄的文本框 所以当我们提交然后在学生姓名前面输入的年龄时,它将与学生姓名和年龄一起存储在表中。 (一次多个学生数据馈送)
最佳答案
您好尝试根据您的更改 table
名称和 column
名称。
我还查询
表
的所有数据,如果年龄已经存在,这将更新
所有字段年龄,并且您再次填写表格。因此,要么在您的查询中应用 where
condition
以便它仅过滤没有价格的名称,或者在 database< 中显示年龄的表单中添加值字段
。(这是根据您在评论中提供的代码)
<?php
$conn = mysqli_connect($mysql_hostname, $mysql_user, $mysql_password,$mysql_database) or die("Could not connect database");
$result = mysqli_query($conn,"select * from user");
if(isset($_POST['submit'])){
$sql = "UPDATE user SET age = (CASE name ";
foreach($_POST['age'] as $key=>$value){
$sql = "UPDATE user SET age = '$value' where name = '$key'";
mysqli_query($conn,$sql);
}
$success = "updated successfully";
}
if(isset($success) && !empty($success)){
echo '<h3>'.$success.'</h3>';
}
echo '<form method="post">';
echo '<table>';
while($row = mysqli_fetch_assoc($result)){?>
<tr>
<td><input type="text" value="<?php echo $row['name']; ?>" name="name" readonly="true"></td>
<td><input type="number" name="age[<?php echo $row['name']; ?>]" placeholder='enter age'></td>
</tr>
<?php } ?>
<tr><td colspan="2">
<input type="submit" name="submit" value="Save"></td></tr>
</table>
</form>
关于php - 将多个文本框的数据插入到单列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38068289/