【发布时间】:2017-10-29 00:06:22
【问题描述】:
我正在处理的这个项目我有一个将结果列出到表中的搜索表单,我在循环中添加了两个提交表单,如果单击应该将结果传输到另一个表。但是当我单击提交按钮时,它只会刷新页面。我已经更改了表单的名称和值,并尝试在 PHP 中输入和输出值中的引号以及其他一些具有相同结果的更改。有什么想法我可能做错了吗?
?>
<table>
<tr>
<th>Name</th>
<th>Brewery</th>
<th>City</th>
<th>State</th>
<th>Style</th>
<th>ABV</th>
<th>IBU</th>
</tr>
<tr>
<td><?php echo $result['Name']; ?></td>
<td><?php echo $result['Brewery']; ?></td>
<td><?php echo $result['City']; ?></td>
<td><?php echo $result['State']; ?></td>
<td><?php echo $result['Style']; ?></td>
<td><?php echo $result['ABV'];?> </td>
<td><?php echo $result['IBU']; ?></td>
<td>
<form method="post" name="ontap" action="form.php">
<input type="hidden" name="name3" value=<?php echo $result['Name'] ?>>
<input type="hidden" name="brewery3" value=<?php echo $result['Brewery']; ?>>
<input type="hidden" name="city3" value=<?php echo $result['City']; ?>>
<input type="hidden" name="state3" value=<?php echo $result['State']; ?>>
<input type="hidden" name="style3" value=<?php echo $result['Style']; ?>>
<input type="hidden" name="abv3" value=<?php echo $result['ABV']; ?>>
<input type="hidden" name="ibu3" value=<?php echo $result['IBU']; ?>>
<input type="submit" name="ontap" value="On Tap">
</form> </td>
<?php
if(isset($_POST['ontap'])){
$name3 = $_POST['name3'];
$brewery3 = $_POST['brewery3'];
$city3 = $_POST['city3'];
$state3 = $_POST['state3'];
$style3 = $_POST['style3'];
$abv3 = $_POST['abv3'];
$ibu3 =$_POST['ibu3'];
mysqli_connect($conn,"INSERT INTO `Test` (`Name`, `Brewery`, `City`, `State`, `Style`, `ABV`, `IBU`) VALUES ('".$name3."', '".$brewery3."', '".$city3."', '".$state3."', '".$style3."', '".$abv3."', '".$ibu3."')") or die(mysqli_error($conn));
echo("Beer Added");
}
?>
<td>
<form method="post" action="form.php" id="bottle">
<input type="submit" name="bottle" value="bottle"> </form></td>
</tr>
</table>
<?php
我在刷新页面时仍然遇到同样的问题。进行了一些建议的更改,但似乎没有任何效果。但到目前为止,mysqli_connect 已更改为 mysqli_query。我已将每个输入名称放入括号 ontap['name3'];等。将操作值留空。我注意到拉入表单的每个变量也只使用第一个单词。我会尝试上传正在使用的表格的图片 searchformwithtable
【问题讨论】:
-
如果您的表单添加了新行,则需要在 SELECT one 之前执行 INSERT 查询。
-
您的表单未提交。将表单中的操作设为空白,即 action=" " 并尝试。
-
我将操作留空并更改为 mysqli_query 但它仍然只是刷新页面。有没有办法查看表单是否正在提交变量值?
标签: php html forms html-table