简体   繁体   English

将复选框值存储在数据库中

[英]store check box value in database

I'm working on the Administrator page for my website. 我正在网站的“ 管理员”页面上工作。

Administrator has the privilege to select six( 6 ) products and change the status from available to unavailable and vice versa, using check box . 管理员有权使用复选框选择六( 6 )个产品,并将状态从可用更改为不可用 ,反之亦然。

Available products will be shown on the front-end for the user to see along with the picture of the product. 可用产品将显示在前端,供用户查看以及产品图片。

I have a table named used and has a column of value ( VarChar ). 我有一个名为used的表,并且具有一列valueVarChar )。

Connection of both user and admin page to the database works fine. 用户页面和管理页面都连接到数据库可以正常工作。 My problem is I'm not sure how to store the value of the selected check boxes , that would change the front end's output (picture of a product on the front-end will show up if product is available). 我的问题是我不确定如何存储所选复选框的值,这会更改前端的输出(如果有可用产品,则会显示前端产品的图片)。

Here are my codes: 这是我的代码:

Admin (not sure at all how to do this) 管理员 (完全不确定如何执行此操作)

Product 1
<input type="checkbox" name="product1" value="1">Available</span></input>

Product 2
<input type="checkbox" name="product2" value="1">Available</span></input>

User 用户

<?php

require_once "../db_connect.php";

$res = mysqli_query("SELECT value FROM settings WHERE name='product1'",$mysql);

$row = mysqli_fetch_array($res);

$product1 = $row['value'];

$res = mysqli_query("SELECT value FROM settings WHERE name='product2'",$mysql);

$row = mysqli_fetch_array($res);

$product2 = $row['value'];


if ($product1 > 0)
    {
    echo '<img src="http://mysite/image1.png" border=0>';
    }
else 
    {
    echo '<img src="http://mysite/image2.png" border=0>';
    }

if ($product2 > 0)
    {
    echo '<img src="http://mysite/image3.png" border=0>';
    }
else 
    {
    echo '<img src="http://mysite/image4.png" border=0>';
    }

?>

for storing check box value use name attribute as 用于存储复选框值,将名称属性用作

$check=$_POST['product1']; //it depend on you what method you are using

if you echo $check it will give 1 如果您回显$ check,它将给出1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM