为了账号安全,请及时绑定邮箱和手机立即绑定

使用复选框php将数据插入mysql数据库

使用复选框php将数据插入mysql数据库

PHP
茅侃侃 2021-06-08 13:42:57
在这里有点恼火,尝试了很多东西,但没有任何效果。我想为我的 Magic the Gathering 粉丝网站最终项目制作一个表格,您可以在其中选择复选框以使用字母或根本不填充数据库中的列。<!Doctype html><html><head></head><body>    <?php    if (!empty($_POST)) {        //connect to the database        $mysqli = new mysqli('localhost', 'root', '', 'magic');        //check the connection        if ($mysqli->connect_error) {            die('Connect Error: ' . $mysqli->connect_errno . ': ' . $mysqli->connect_error);        }        //insert the data        $sql = "INSERT INTO decks ( DeckName, Author, CardList ) VALUES ( '{$mysqli->real_escape_string($_POST['DeckName'])}', '{$mysqli->real_escape_string($_POST['Author'])}', '{$mysqli->real_escape_string($_POST['CardList'])}' )";        $insert = $mysqli->query($sql);        //insert the checkbox data        if (isset($_POST['Red'])) {            $sql = "INSERT INTO decks ( Red ) VALUES ( '{$mysqli->real_escape_string('R')}' ) ";        } else {            $sql = "INSERT INTO decks ( Red ) VALUES (' ')";        }        //response from the database        if ($insert) {            echo "Success!";        } else {            die("Error, please try again!");        }        //kill the connection        $mysqli->close();    }    ?>    <form method="post" action="">        <input name="DeckName" type="text">        <br>        <br>        <input name="Author" type="text">        <br>        <br>如果复选框被选中,我希望它在列中放置一个 R,如果没有,则什么都不做。没有任何东西进入专栏。
查看完整描述

3 回答

?
慕哥6287543

TA贡献1831条经验 获得超10个赞

In HTML

    <label> Language</label>

    <input type="checkbox" name="lan[]" value="eng">English

    <input type="checkbox" name="lan[]" value="tam">Tamil

    <input type="checkbox" name="lan[]" value="tel">Telugu

    <input type="checkbox" name="lan[]" value="hin">Hindi    

In php

    $lan=$_POST["lan"];

    $slan=implode[","$lan];


查看完整回答
反对 回复 2021-06-12
  • 3 回答
  • 0 关注
  • 135 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信