php - 使用从 html 下拉列表中选择的 SQL 数据
问题描述
新手警报我已经阅读了几个小时,但看不到如何做我想做的事。我有一个带有药物和剂量等列表的 SQL 数据库。我试图创建一个“编辑”页面,以便我可以从下拉列表中选择药物(这似乎有效),并编辑它的某些部分(大小、框数量、剂量等
问题是我无法让选定的药物项目(从下拉菜单)成为一个变量,或者如果有必要,转发到第二个 PHP 页面。我在那里留下了一些尝试编辑,但它们导致错误(TRIED NOT WORK)事实上,它正在加载editmed.php以在提交时加载我的编辑页面。(不确定这是否是最好的方法)。
任何帮助都会非常感谢
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Editor</title>
<link rel="stylesheet" href="global.css">
</head>
<body>
<div class="header">
<h1>Edit Medication Item</h1>
</div>
<div class="topnav">
<a href="indexhl.php">Home</a>
<a class="active" href="edit.php">Edit Medication</a>
<a href="presc_coll.php">Prescription Collection</a>
<a href="add-new.php">Add New Medication</a>
<a href="pillbox.php">Pillbox refill</a>
<a href="individualtopup.php">Individual refill</a>
</div>
<?php
// server connect
$mysqli = new mysqli("localhost:port", "USERNAME", "PASSWORD", "prescription")
or die ('Cannot connect to db');
// select medication name field from db
echo "<p><b><U><i><p style='color:red'>Select Medication</I></U></p><p style='color:black'></b></p>";
$sqlSelect="select Medication from general";
$result = $mysqli -> query ($sqlSelect);
//$medselect=$result['Medication'];**TRIED NOT WORK**
echo "<form action='editmed.php'>";
echo "<select id=`Medication` name=`medselect`>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='" . $row['Medication'] . "'>" . $row['Medication'] . "</option>";
}
//$medselect=$result['Medication'];**TRIED NOT WORK**
echo "</select>";
echo "<input type='submit' value='submit'>";
// echo "<input type='submit' value='<$medselect>' name='medselect'/>" ; **TRIED NOT WORK**
echo "</form>" ;
echo "</body>";
echo "</html>";
?>
</body>
</html>
编辑过的.php >
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Editor</title>
<link rel="stylesheet" href="global.css">
</head>
<body>
<div class="header">
<h1>Edit Medication Item</h1>
</div>
<div class="topnav">
<a href="indexhl.php">Home</a>
<a class="active" href="edit.php">Edit Medication</a>
<a href="presc_coll.php">Prescription Collection</a>
<a href="add-new.php">Add New Medication</a>
<a href="pillbox.php">Pillbox refill</a>
<a href="individualtopup.php">Individual refill</a>
</div>
<?php
// server connect
$link = mysqli_connect("localhost:port", "user", "password",
"prescription")
or die ('Cannot connect to db');
// $sql = "SELECT ID, Medication, dosagedaily, Box_Size, Boxed_remain,
grandtotal, last_collected, Dosage, countdown FROM general where
`Medication` = $medselect";
$sql = "SELECT ID, Medication, dosagedaily, Box_Size, Boxed_remain,
grandtotal, last_collected, Dosage, countdown FROM general where
`Medication` = 'Esomeprazole 40mg'";
// you check sql and link true
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>Index</th>";
echo "<th>Medication</th>";
echo "<th>Daily Dosage</th>";
echo "<th>Box Size</th>" ;
echo "<th>Boxed Remaining</th>" ;
echo "<th>Grand Total</th>";
echo "<th>Last presc collection</th>";
echo "<th>Dosage</th>";
echo "<th>Pills Remaining</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['Medication'] . "</td>";
echo "<td>" . $row['dosagedaily'] . "</td>";
echo "<td>" . $row['Box_Size'] . "</td>";
echo "<td>" . $row['Boxed_remain'] . "</td>";
echo "<td>" . $row['grandtotal'] . "</td>";
echo "<td>" . $row['last_collected'] . "</td>";
echo "<td>" . $row['Dosage'] . "</td>";
echo "<td>" . $row['countdown'] . "</td>";
echo "</tr>";
}
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "No records matching your query were found.";
}
}
else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
我不知道如何从输入表单中分配变量,这就是我的问题所在。如果我分配了一个变量,那么我可以创建实际的编辑部分。
解决方案
推荐阅读
- mysql - 用于测试 Django 应用程序的 MySQL 用户权限
- javascript - 如果 url 页面有他的类,则添加按钮类活动
- node.js - str.includes 不是函数 // superagent
- javascript - onclick 和 ontouchstart 不适用于任何元素的移动设备
- c# - 计算井字游戏获胜者 C# || 在线练习评估试题 ||
- node.js - 使用 Firebase Cloud Functions 扇出数据
- hadoop - Ranger 显示用于授予访问权限的 Hadoop-ACL 而不是 Ranger-ACL
- reactjs - Sending 'sent' data from a page to a component in Gatsby
- html - Angular Material Forms 和 Flex Layout - 在所有行中获得相等的输入宽度
- javascript - 错误 [ERR_MODULE_NOT_FOUND]:找不到包 'src'