我一直致力于一个用户选择他的userame和日期范围的项目,当点击提交时,会出现一个html表。现在用户必须在其中一个中填写一个输入字段(下拉列表)。列和单击提交后,输入数据应相应地存储在数据库中。我设法将表格(下拉)放在正确的位置,但我如何调用所选数据并将其保存到数据库中。
<?php
if (isset($_POST['submitted'])) {
include ('connect.php');
$username = $_POST['user'];
$from = $_POST['from'];
$to = $_POST['to'];
$query = "SELECT * FROM errorreport WHERE user = '$username' AND date BETWEEN '$from' AND '$to' ORDER BY date DESC";
$result = mysqli_query($dbcon, $query) or die ('cant find data');
$num_rows = mysqli_num_rows($result);
echo "welcome '$username' \n '$num_rows' results found";
echo "<table>";
echo "<table border='1' width:'100%'>";
echo "<tr><th>DATE</th><th>TASK_QUEUE</th><th>AUDIO</th><th>TRANSCRIBED</th><th>VERIFIED</th><th>OVERTURNED_FIELDS</th><th>TYPE OF ERROR</th><th>BLUESHIFT_LINK</th></tr>";
echo "<form action='insert.php' method='post'>";
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo $row['OVERTURNED_FIELDS'];
echo "</td><td>";
echo "<select name = error_type>";
echo "<option value= > </option>
<option value=Convention Error>Convention Error</option>
<option value=Listening Error>Listening Error</option>
<option value=Referencing Error>Referencing Error</option>
<option value=Spelling/Typos>Spelling/Typos</option>
<option value=Metadata Error>Metadata Error</option>
</select>";
echo "</td><td>";
echo "<a href=".$row['BLUESHIFT_LINK'].">Click Here </a>";
echo "</td></tr>";
}
echo "</table>";
echo "<input type=submit value=submit>";
echo "</form>";
}
?>
I get this error message when i submit.
请在下面找到insert.php代码。
<?php
DEFINE ('DB_USER', 'root');
DEFINE ('DB_PSWD', '');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'testdb');
$dbcon = mysqli_connect(DB_HOST, DB_USER, DB_PSWD, DB_NAME);
if(!$dbcon)
{
echo 'not connected to server';
}
if(!mysqli_select_db($dbcon,'testdb'))
{
echo 'database not selected';
}
$errortype = $_POST['error_type'];
$audio=$_POST['audio'];
$username=$_POST['name'];
$sql = "UPDATE errorreport SET error_type = '$errortype' WHERE user= '$username' and audio = '$audio'";
if(!mysqli_query($dbcon,$sql))
{
echo 'not inserted';
}
else
{
echo 'inserted';
}
header("refresh:100; url=select1.php");
?>
<html>
<head>
<title>Welcome to Error Report Portal </title>
<style type="text/css">
table {
background-color: #FFFACD;
}
th {
width: 150px;
text-align: center;
}
</style>
</head>
<body>
<h1> Welcome to Error Report Portal! </h1>
</body>
</html>
答案 0 :(得分:0)
这些通知是因为您创建了名为error_type的选择框,因此$ _POST [&#39; error_type&#39;];可以访问,但$ _POST [&#39;音频&#39;]和$ _POST [&#39;名称&#39;]没有带有这些名称的输入字段,所以只提醒通知
1.请为name属性创建两个带有这些名称和音频的输入字段 2.或使用这样的属性 $音频= @ $ _ POST [&#39;音频&#39;]; $ USERNAME = @ $ _ POST [&#39;名称&#39;];
3.请使用这样的查询进行良好的编程练习...
"UPDATE errorreport SET error_type = '".$errortype."' WHERE user= '".$username."' and audio = '".$audio."'"
答案 1 :(得分:0)
创建两个隐藏的输入字段,将名称和audiolink作为控件的值进行回显。例如。
<input type="hidden" name="name" value="<?php echo $name;" />