出于某种原因,当我点击按钮显示时,我的数据没有出现在网页上。它几天前工作,但现在不是。我不记得做出任何重大改变。有谁知道发生了什么事?
代码:
<html>
<head>
<title>Database</title>
</head>
<body>
<div id="casing">
<form action="filmsdatabase.php" method="GET">
<div id="Films"><input type="submit" name="button" value="show films" /></div>
</form>
</div>
<?php
$db = mysql_connect("cs4111.cshve4dssdhm.us-west-2.rds.amazonaws.com","username","password");
if (!$db) {
die("Database connection failed miserably: " . mysql_error());
echo "Failed to Connect";
}
$db_select = mysql_select_db("cs4111",$db);
if (!$db_select) {
die("Database selection also failed miserably: " . mysql_error());
echo "Failed to Connect";
}
if(isset ($GET["button"]) && $GET["button"] == "show films"){
$result = mysql_query("SELECT * FROM films", $db);
if (!$result) {
die("Database query failed: " . mysql_error());
}
while ($row = mysql_fetch_array($result)){
echo "<h2>";
echo $row[1]."";
echo "</h2>";
echo "<p>";
echo $row[2]."";
echo "</p>";
echo "Duration: ", $row[3]."", " minutes";
echo "</p>";
echo "Genre: ", $row[4]."";
echo "</p>";
}
}
?>
</body>
</html>
<?php
mysql_close($db);
?>
答案 0 :(得分:2)
快速浏览一下这里的代码,我认为你实际上是想使用$ _GET而不是$ GET。
if(isset ($_GET["button"]) && $_GET["button"] == "show films"){
这使用PHP $ _GET全局变量。