我有我無法解決的錯誤。我有兩種形式的提交按鈕:輸入名稱以兩種不同形式更改,從而導致名稱解決錯誤
<form name="form_1" action=<?php echo $_SERVER['PHP_SELF'] ;?>>
<input type="text" name="search_1" value="<?php echo $_GET['search'] ; ?>">
<input type="submit" value="Search by Name">
</form>
<form name="form_2" action=<?php echo $_SERVER['PHP_SELF'] ;?>>
<input type="text" name="search_2" value="<?php echo $_GET['search'] ; ?>">
<input type="submit" value="Search by Message">
</form>
錯誤說:search_1是未定義的。它怎麼可能是未定義的? 順便說一句,如果我使兩個表單輸入名稱相同:search
一切正常,但正常情況下,如果我把價值在一種形式,得到相同的輸入以其他形式也。 我做錯了什麼?
爲form_1 PHP代碼:
<?php
// Check if the form has been sent or if the page was accessed using the GET method.
if(filter_input(INPUT_SERVER, "REQUEST_METHOD") !== "GET") {
die();
}
$search = filter_input(INPUT_GET, "search");
// Check if the searh input has been correctly fill
if(!isset($search)) {
die();
}
// Let's return here to prevent open an empty file
if(filesize($file) <= 0) {
return;
}
$openedFile = fopen($file, "r");
// I was using the here document option, echo <<<END END; but it didn't work due to my text editor...
echo "
<table width=50% border=1>
<thead>
<tr>
<th>Name</th>
<th>Nick</th>
<th>Message</th>
</tr>
</thead>
<tbody>
";
// Let's save in buffer the current line and then navigate through all of them
while(($buffer = fgets($openedFile, 4096)) !== false) {
$part = explode("|", $buffer);
// Here we check if the line has the searched word
if(strpos($part[0], $search) !== false && $search != '') {
echo "
<tr>
<td>" . $part[0] . "</td>
<td>" . $part[1] . "</td>
<td>" . $part[2] . "</td>
</tr>
";
}//.if
}//.while
echo "
</tbody>
</table>
";
?>
一個提交HTML表單內按鈕只提交_that_形式,而不是其他的。 – arkascha
你能顯示php代碼片段嗎? –
@PartharajDeb這與php無關... – arkascha