【发布时间】:2019-08-07 15:15:56
【问题描述】:
我的任务是在 phpMyAdmin 中创建两个表,然后创建一个简单的表单,用户可以在其中单击一个按钮并显示这两个表。我已经完成了作业的登录页面,其中包含标题、搜索栏和按钮,但我无法弄清楚如何从数据库中导入这两个表并在单击按钮后显示它们。
我在一些代码方面得到了导师的帮助,但我无法让它正常工作,希望得到任何进一步的帮助。
这是我现在拥有的代码(两个单独的 php 代码块是人们试图帮助我做到这一点的两种方式,但我不知道哪种方式有效或如何实现它):
<!DOCTYPE html>
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) {die("Connection Failed: " . $conn->connect_error);
}
echo "Connected Successfully";
?>
<html>
<head>
</head>
<body>
<h1>Health Club Patron and Class Information</h1>
<form name="contact-form" action="" method="post" id="contact-form">
<div class="form-group">
<label for="Search">Search</label>
<input type="text" class="form-control" search="your_name" placeholder="Search" required>
</div>
<button type="print" class="btn btn-primary" name="print" value="Print" id="submit_form">Print</button>
</form>
</body>
</html>
$connection = mysql_connect('localhost', 'root', ''); //The Blank string is the password
mysql_select_db('hrmwaitrose');
$query = "SELECT * FROM employee"; //You don't need a ; like you do in SQL
$result = mysql_query($query);
echo "<table>"; // start a table tag in the HTML
while($row = mysql_fetch_array($result)){ //Creates a loop to loop through results
echo "<tr><td>" . $row['name'] . "</td><td>" . $row['age'] . "</td></tr>"; //$row['index'] the index here is a field name
}
echo "</table>"; //Close the table in HTML
mysql_close(); //Make sure to close out the database connection
【问题讨论】:
-
从您的角度了解问题非常具体,您的问题过于宽泛,参与者可能会认为您是在要求他们为您完成工作。我建议您返回并选择与您的问题相关的基本 php 领域,然后 - 如有必要 - 回来并用您仍然遇到问题的部分更新问题。跨度>
标签: javascript html database phpmyadmin