doujing5846 2011-12-12 19:38
浏览 33
已采纳

将Multiple Form选择插入Mysql

Need help with PHP Mysql code to insert multiple select data into database. With the current code i only get "Arry" in the ccaid field in the MySQL database, it should contain the Md5 code generated by first code.

Here is the code for Multiple Select data:

<?php   include ('incl/_dbconnection.php');
        include ('incl/_dbopen.php');
        include ('_header.php'); 

        $base1 = '<option value="';
        $base2 = '">';
        $base3 = '</option>';

$updatekey = md5(uniqid(mt_rand(), true));
$clientId = md5(uniqid(mt_rand(), true));

$subject = 'Complete your Registration';

mysql_query("INSERT INTO clients (clientid, cname, caddress, ctel, cfax, cmobile, cemail, cperson, cdescription, cproducts, cupdatekey, cwebsite, clastip, cvalidated)
VALUES ('$clientId', '$_POST[company]', '$_POST[address]', '$_POST[tel]', '$_POST[fax]', '$_POST[mobile]', '$_POST[email]', '$_POST[person]', '$_POST[description]', '$_POST[products]', '$updatekey', '$_POST[website]', '$_POST[ipaddress]', '$_POST[validate]')");

?>
<div class="full-width-wrapper">
                <div class="fixed-width-wrapper" id="body-content">
                    <div id="content" class="float-left content-left">
                            <h1 class="first-word sp">
                                <strong>Client Registered!</strong>
                            </h1>
                        <div id="mlogin" class="clear">
                            <h2 align="center"><strong>Choose Categories!</strong></h2>
                            <br/>
                            <table width="100%" border="0" class="m-table">
<thead>
  <tr>
    <td colspan="2" scope="col">
                        <div class="formRight">
                            <form action="registration_complete.php?id=<?php echo $clientId ;?>" method="post">
                            <select multiple="multiple" class="multiple" title="" name="categories[]">
                            <?php $SQL = "SELECT * FROM wdcategories ORDER BY `caname` ASC";
    $result = mysql_query($SQL);

    while ($db_field = mysql_fetch_assoc($result)) {

    echo $base1;
    print $db_field['caid'];
    echo $base2;
    print $db_field['caname'];
    echo $base3;

    };?>
                            </select>
                            <br/><br/><br/>
                            <button type="submit" class="black border-radius-3px bold submit" title="">
                                    Complete Registration
                                </button>
                            </tr>
  </thead>
</table></form>
                            <div class="clear">
                            </div>
                        </div>
                    </div>
<?php   
        include ('_footer.php'); 
        include ('incl/_dbclose.php');
?>

Here is the code that insert the multiple select data into the database:

<?php   include ('incl/_dbconnection.php');
        include ('incl/_dbopen.php');
        include ('_header.php'); 

        $id=$_GET['id'];

        $categories = $_POST['categories'];
for ($i = 0; $i < count($categories); $i++) {
    $category = $categories[$i];
    mysql_query("INSERT INTO ccategories (ccaid, cclientid) VALUES ('" . $_POST['categories'] . "','$id')");
} 

?>
<div class="full-width-wrapper">
                <div class="fixed-width-wrapper" id="body-content">
                    <div id="content" class="float-left content-left">
                            <h1 class="first-word sp">
                                <strong>Client Listed!</strong>
                            </h1>
                        <div id="mlogin" class="clear">
                            <h2 align="center"><strong>Registration Completed!</strong></h2>
                            <br/>
                            <img src="images/success.png" width="256" height="256">
                            <br/>
                            <h3 align="center"><a href="index.php">Click Here to add another Client</a></h3>
                            <div class="clear">
                            </div>
                        </div>
                    </div>
<?php 
        include ('_footer.php'); 
        include ('incl/_dbclose.php');
?>
  • 写回答

1条回答 默认 最新

  • duanqian9593 2011-12-12 19:42
    关注
    mysql_query("INSERT INTO ccategories (ccaid, cclientid) VALUES ('" . $_POST['categories'] . "','$id')");
    

    ...should be...

    mysql_query("INSERT INTO ccategories (ccaid, cclientid) VALUES ('" . $category . "','$id')");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi