使用单选按钮插入功能

时间:2015-11-30 20:18:43

标签: radio-button sql-insert

所以我的问题是我无法使用单选按钮将数据插入到选定的表中。单选按钮用于告诉我们需要访问哪个表并添加数据。我认为我说得对,但它不起作用。这就是我所拥有的。任何形式的帮助将不胜感激。

<h1 align="center">Event</h1>
<h1 align="center"><a href="stroage.html" target="new">Storage</a></h1>
<form action="set_event.php" method="post">
<p>
<p>
<input type="submit" name="submit" value="Set Items">
</p>
<p>
<br>
<label>
<input type="radio" name="storage" value="concourse_stairs_s" id="s1">
Concourse Stairs</label>
<br>
<label>
<input type="radio" name="storage" value="bat_cave_s" id="s2">
Bat Cave</label>
<br>
<label>
<input type="radio" name="storage" value="fireside_s" id="s3">
Fireside Storage</label>
<br>
</p>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {

require ('mysqli_connect.php'); // Connect to the db.

$errors = array(); // Initialize an error array.

}


if (isset($_REQUEST['bat_cave_s']))
{
$q = "INSERT INTO bat_cave_s (item_name, check_in) VALUES ('test', NOW())";    
$r = @mysqli_query ($dbc, $q); // Run the query.
}
else if(isset($_REQUEST['concourse_stairs_s']))
{
$q = "INTO concourse_stairs_s (item_name, check_in) VALUES ('test', NOW())";    
$r = @mysqli_query ($dbc, $q); // Run the query.
}
else if(isset($_REQUEST['fireside_s']))
{
$q = "INSERT INTO fireside_s (item_name, check_in) VALUES ('test', NOW())";    
$r = @mysqli_query ($dbc, $q); // Run the query.
}
NOW())";

1 个答案:

答案 0 :(得分:0)

您的PHP检查错误。

您需要检查$_REQUEST['storage']

的值
if($_REQUEST['storage'] == 'bat_cave_s') {