dongxi8993 2009-08-19 12:40
浏览 123

使用PHP将二进制复选框值添加到MySQL数据库

I'm new to PHP, and I am creating a basic CMS using PHP and MySQL. I'm struggling to get the checkbox information from my HTML page across into the database.

How can I make the values to appear as binary 0 or 1 values?

The HTML document is written as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Create your news page</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
        <fieldset>
            <legend>Checked components will show in the page</legend>
            <form method="POST" action="http://*********.php">
                <span class="label">Header</span>
                <input type="checkbox" name="header" value="HEADER">
                <br>
                <span class="label">Footer</span>
                <input type="checkbox" name="footer" value="FOOTER">

                <hr>
                <span class="label">Local news</span>
                <input type="checkbox" name="local" value="LOCALNEWS">
                <br>
                <span class="label">National news</span>
                <input type="checkbox" name="national" value="NATIONALNEWS">
                <br>
                <span class="label">International news</span>
                <input type="checkbox" name="international" value="INTERNATIONALNEWS">
                <p>
                <input type="submit">
            </form>
        </fieldset>
    </body>
</html>

And the PHP document is written as follows:

<?php
    $user="user_***";
    $password="*********";
    $database="dbxyz";
    mysql_connect("localhost", $user, $password);
    mysql_select_db($database, $db_handle);
    mysql_select_db("dbxyz");
    if(isset($_POST['layout']))
    {
        foreach($_POST['layout'] as $value {
            $insert="INSERT INTO layout (header, footer, local, national, international) VALUES ('$value')";
            mysql_query($insert);
        }
    }
?>
  • 写回答

4条回答 默认 最新

  • douyi9787 2009-08-19 12:46
    关注

    I think you're looking for the MySQL 'BOOL'-datatype...

    Edit: Your code is actually loaded with syntax/code errors... I don't believe this actually runs. Can you paste the original here?

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图