我可以使用outset($ post [])为以下代码编写

时间:2016-06-26 06:40:45

标签: javascript php post isset



<script>
function removeAllRowsContainingCheckedCheckbox() {
  alert("hello");
    for (var rowi= table.rows.length; rowi-->0;) {
        var row= table.rows[rowi];
        var inputs= row.getElementsByTagName('input');
        for (var inputi= inputs.length; inputi-->0;) {
			//alert("inside for");
            var input= inputs[inputi];

            if (input.type==='checkbox' && input.checked) {
			//alert("indide if ")
                row.parentNode.removeChild(row);
                break;
            }
        }
    }
}


</script>
&#13;
<html>  
<head>

</head>
<body>  
   <form action="" method="post" enctype="multipart/form-data">  
  
<table border="1" id="table">  
   <tr>  
      <td colspan="2">Select Technolgy:</td>  
   </tr>  
   <tr>  
      <td>c</td>  
      <td><input type="checkbox" name="techno[]" ></td>  
   </tr>  
   <tr>  
      <td>hadoop</td>  
      <td><input type="checkbox" name="techno[]" ></td>  
   </tr>  
   <tr>  
      <td>core java</td>  
      <td><input type="checkbox" name="techno[]" ></td>  
   </tr>  
   <tr>  
      <td>Javascript</td>  
      <td><input type="checkbox" name="techno[]" ></td>  
   </tr>  
   <tr>  
      <td>springs</td>  
      <td><input type="checkbox" name="techno[]" ></td>  
   </tr>
   <tr>  
      <td colspan="2" align="center"><input type="submit" value="submit" name="sub"></td>  
   </tr>
	     
      <input type='button' value='del' onclick='removeAllRowsContainingCheckedCheckbox();'>Click me to delete
</table>  
 
</form>  
<?php  
if(isset($_POST['sub']))  
{  
 $db = pg_connect("host=localhost port=5432 dbname=postgres user=postgres password=ndem$123");
 if(!$db){
      echo "Error : Unable to open database\n";
   } else {
      echo "Opened database successfully\n";
   }

 
$checkbox1=$_POST['techno'];  
$chk="";  
foreach($checkbox1 as $chk1)  
   {  
      $chk .= $chk1."";  
	   echo '<script>alert("Inserted Successfully")</script>';
   }  
$in_ch=pg_query("insert into news_table(technology) values ('$chk')");  
echo "the check box value is " . $in_ch;
if($in_ch==1)  
   {
	 echo '<script>alert("Inserted Successfully")</script>';
	 echo "Records created successfully\n";
   }  
else  
   {  
     echo pg_last_error($db);
   }  
   pg_close($db);
}  
?>  
</body>  
</html>  
&#13;
&#13;
&#13;  对于提交,我可以使用

编写javascript函数
$checkbox1=$_POST['techno'];  
    $chk="";  
    foreach($checkbox1 as $chk1)  
       {  
          $chk .= $chk1."";  
           echo '<script>alert("Inserted Successfully")</script>';
       }

上面的代码,因为if(isset($ _ POST [&#39; sub&#39;]))正在重新加载表中已经提交的复选框,这样用户可能会在删除后混淆页面将再次显示所有复选框的那些人也提交..请为此建议替代方法我想将选中的复选框插入数据库,但我的想法是删除表中提交的已检查。

0 个答案:

没有答案