我的代码将多个选定的值插入到两列中,但两列都包含第一个列出(选定)复选框的值。例如。如果我选择了 .Net2 和 Java3,两个 cloumns 将受到影响,但它们的值都为 2。<form action="" method="post" > <div style="width:200px;border-radius:6px;margin:0px auto"> <table border="1"> <tr> <td colspan="2">Select Technolgy:</td> </tr> <tr> <td>PHP1</td> <td><input type="checkbox" name="techno[]" value="1"></td> </tr> <tr> <td>.Net2</td> <td><input type="checkbox" name="techno[]" value="2"></td> </tr> <tr> <td>Java3</td> <td><input type="checkbox" name="techno[]" value="3"></td> </tr> <tr> <td>Javascript4</td> <td><input type="checkbox" name="techno[]" value="4"></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="submit" name="sub"></td> </tr> </table> </div> </form> <?php if(isset($_POST['sub'])) { $connection = mysqli_connect("localhost", "root", ""); // Establishing Connection with Server $db = mysqli_select_db($connection, "ofobms"); // Selecting Database from Server // Check connection if (!$connection) { die("Connection failed: " . mysqli_connect_error()); } $checkbox1=$_POST['techno']; //$hobb= $_POST['Hobbies']; $chk=""; foreach($checkbox1 as $chk1) { $chk .= $chk1.","; } $N = count($checkbox1); echo("<p>You selected $N techno(s): "); for($i=0; $i < $N; $i++) { $in_ch=mysqli_query($connection,"INSERT INTO order_table (item_ID) values ('$chk')"); } if($in_ch==2) { echo'<script>alert("Inserted Successfully")</script>'; } else { echo'<script>alert("Failed To Insert")</script>'; } } ?>这就是我现在的桌子的样子| item_ID || 2 | 2我希望它是这样的,第二列保持值 3| item_ID || 2 | 3
1 回答
- 1 回答
- 0 关注
- 149 浏览
添加回答
举报
0/150
提交
取消