我想要得到一個isset,因此如果我的表單中的sumbit按鈕沒有被點擊,代碼就會停止。然而,我所做的每件事都會讓它認爲按鈕從不按下。我可以使用一些幫助。對不起,巨大的代碼轉儲。PHP提交按鈕檢查不工作
if(!$ gn === null)是我試圖讓它工作的可悲嘗試。
謝謝
<!--*** Form Start ***-->
<form method="post" name="Lab4Form" id="Lab4Form"
action="genre_aries0653.php">
<fieldset>
<legend>Select by Genre</legend>
<!-- Genre -->
<label for="genre">Genre: </label>
<input type="text" name="genre" id="genre" size="50"
maxlength="35" placeholder= "Freedom"
required="required"><br><br>
<!--Submit/Reset Buttons -->
<input type="submit" value="Submit" id="submit">
<input type="reset">
</fieldset>
</form>
<?php
//require_once functions
require_once ("inc_functions_aries0653.php");
//require_once connect to db, selects db
require_once("conn_aries0653.php");
$gn = (filter_input(INPUT_POST, 'genre'));
$genre = (ucwords(strtolower(trim($gn))));
if (!$gn===null) {
} else {
die;
}
MultiCheck ($genre);
//Checks if connected to database successfully
$dbConnection = new mysqli($sn, $un, $pw, $dbName);
if ($dbConnection->connect_error)
{
die ("Connection Failed: ".$dbConnection->connect_error);
}
//Declares the sort and SQL string
$sort = "author_lastName";
//SQL: Select all from table, where genre = user input genre, sort
$sqlQuery =
"SELECT * FROM $tableName WHERE genre= '$genre' ORDER BY $sort";
//run query
$result = $dbConnection->query($sqlQuery);
//check if there is any data
if ($result-> num_rows > 0)
{
//Prints the table head which are the fields of the table
$totalRecords = $result-> num_rows;
print("<table border=\"1\"<tr><header><h1>Book Inventory</h1></header></tr>".
"<tr><th>Book Title</th>".
"<th>Author's First Name</th>".
"<th>Author's Last Name</th>".
"<th>Genre</th>".
"<th>ISBN13</th>".
"<th>Publisher</th>".
"<th>Copyright Year</th>".
"<th>Price</th></tr>");
while($record = $result->fetch_assoc())
{
//Loops through the table to retrieve all the records of the given fields
print("<tr><td>{$record['title']}</td>");
print("<td>{$record['author_firstName']}</td>");
print("<td>{$record['author_lastName']}</td>");
print("<td>{$record['genre']}</td>");
print("<td>{$record['ISBN']}</td>");
print("<td>{$record['publisher']}</td>");
print("<td>{$record['yearPublished']}</td>");
//format price to have 2 decinmal places and a "$" sign
print("<td class=\"number\">"."$".number_format("{$record['price']}",2)."</td></tr>\n");
}
//Tell user how many records are returned
print("<tr><td colspan=8 class=message>Your query returned ".
$totalRecords." books.</td></tr>");
print("</table>\n");
} else {
print("No books for you!");
die;
}
//Close db connection
$dbConnection -> close();
?>`
Multicheck是我用來過濾輸入的正則表達式更多 – thelaughingman