<?php
$DatabaseServer = "localhost";
$DatabaseUsername = "root";
$DatabasePassword = "root";
$DatabaseName = "demo";
$Connection = mysqli_connect($DatabaseServer, $DatabaseUsername, $DatabasePassword, $DatabaseName);
if ($Connection === false) {
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sqlusers = "select * from user";
$result = mysqli_query($Connection, $sqlusers);
echo "<form method='POST'>";
while($rowuser = mysqli_fetch_array($result)){
$user = $rowuser['FirstName'];
echo "<input type='text' name='firstName' value='$user' readonly>";
echo "<select name='attendanceType'>";
$sqltype = "select * from attendancetype";
$resultaType = mysqli_query($Connection, $sqltype);
while($rowtype = mysqli_fetch_array($resultaType)){
echo "<option>";
echo $rowtype['name'];
echo "</option>";
}
echo "</select>";
echo "<br>";
}
echo "<input type='submit' name='submit' value='submit'>";
echo "</form>";
?>
用户表。
INSERT INTO `user` (`UserID`, `FirstName`, `LastName`, `Email`, `Password`, `City`) VALUES
(7, 'Rahul', 'Rajshekaran', 'Rahul@zzz.xxx', 'Rahul@123', 'Pune'),
(8, 'Mahesh', 'Krishna', 'Mahesh@xxx.xxx', 'Mahesh@123', 'Delhi');
出勤类型表:
INSERT INTO `attendancetype` (`attendanceTypeID`, `name`) VALUES
(0001, 'Present'),
(0002, 'Absent');
如何在单次提交表单时将数据插入表格?
答案 0 :(得分:0)
你的代码有一个错误。如果要循环表单元素,则必须实现每个输入都具有唯一名称。
databaseReference.child("notifications/"+uuid+"/data_notification").orderByChild("status").startAt("read").endAt("unread").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot) {.....
//add items to list (like you did)
@Override
public void onChildChanged(DataSnapshot dataSnapshot) {.....
//set the items again to the list (update them here) and notify
//data set changed (so values update in your list).
处理表格:
$i = 0;
while($rowuser = mysqli_fetch_array($result)){
$user = $rowuser['FirstName'];
echo "<input type='text' name='firstName[".$i."]' value='$user' readonly>";
echo "<select name='attendanceType[".$i."]'>";
$sqltype = "select * from attendancetype";
$resultaType = mysqli_query($Connection, $sqltype);
while($rowtype = mysqli_fetch_array($resultaType)){
echo "<option>";
echo $rowtype['name'];
echo "</option>";
}
echo "</select>";
echo "<br>";
$i++;
}
escapeFunction用作事实的参考者,你应该以某种方式逃避(有更多的方法)每个输入,并且需要替换或定义