我有这样PHP更新多个选择选项值
CREATE TABLE IF NOT EXISTS `ia_pages` (
`pages_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`page_name` varchar(255) NOT NULL,
`search_type` varchar(120) NOT NULL,
`search_block_position` varchar(255) NOT NULL,
PRIMARY KEY (`alphabet_search_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
INSERT INTO `ia_pages` (`pages_id`, `page_name`, `search_type`, `search_block_position`) VALUES
(1, 'home_page', 'product_search', 'right_column'),
(2, 'product_page', 'category_search', 'right_column'),
(3, 'category_page', 'product_search', 'right_column');
数据库和HTML表单如
<table id="admin-settings">
<tbody>
<tr>
<th>Page Name</th>
<th>Search Type</th>
<th>Show Search in Block</th>
</tr>
<tr>
<td>Home Page</td>
<td>
<select id="search_type" name="search_type">
<option value="product_search">Product Search</option>
<option value="category_search">Category Search</option>
</select>
</td>
<td>
<select id="show_block" name="show_block">
<option value="left_column">Left Column</option>
<option value="right_column">Right Column</option>
</select>
</td>
</tr>
<tr>
<td>Product page</td>
<td>
<select id="search_type" name="search_type">
<option value="product_search">Product Search</option>
<option value="category_search">Category Search</option>
</select>
</td>
<td>
<select id="show_block" name="show_block">
<option value="left_column">Left Column</option>
<option value="right_column">Right Column</option>
</select>
</td>
</tr>
<tr>
<td>Category page</td>
<td>
<select id="search_type" name="search_type">
<option value="product_search">Product Search</option>
<option value="category_search">Category Search</option>
</select>
</td>
<td>
<select id="show_block" name="show_block">
<option value="left_column">Left Column</option>
<option value="right_column">Right Column</option>
</select>
</td>
</tr>
<tr>
<td style="text-align:center;" colspan="4">
<input type="submit" name="submit" value="save" class="button">
</td>
</tr>
</tbody>
</table>
现在,当我选择的任何值时,所做的任何更改窗体并单击,然后使所有行的值相同。 我的更新查询是这样
$host = 'localhost';
$username = 'root';
$username = 'root';
$dbname = 'ia_pages';
$con=mysqli_connect($host,$username,$username);
mysqli_select_db($con,$dbname) or die ("no database");
if (mysqli_connect_errno($con)) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$search_type = $_POST['search_type'];
$show_block = $_POST['show_block'];
if(isset($_POST['submit'])) {
$update_query = "UPDATE `pages` SET `search_type` = '$search_type',`search_block_position` = '$show_block'";
$query_execute = mysqli_query($con, $update_query);
if($query_execute) {
echo "Data has been updated";
} else {
echo "data has not been updated";
}
}
这正在改变甚至唯一的选择已经改变了所有的值。所以数据库中的所有值都被转换为相同的值。那么如何解决这个问题?我想更新前端已更改的数据库中的值。
您有两个名字为“show_block”和“search_type”的下拉菜单。 –
有没有更好的方法来做到这一点的好方法? – Jagdish