我的代碼將多個選定的值插入到兩列中,但兩列都包含第一個列出(選定)復選框的值。例如。如果我選擇了 .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>'; } } ?>這就是我現(xiàn)在的桌子的樣子| item_ID || 2 | 2我希望它是這樣的,第二列保持值 3| item_ID || 2 | 3
- 1 回答
- 0 關注
- 161 瀏覽
添加回答
舉報
0/150
提交
取消