php - If uncheck the check box delete row in my SQL table -


actually new php.. have task select records database checkboxes checked. when uncheck checkbox should delete particular record database..

my code

<?php    if(isset($_post['delete']))        {         $test=$_post['test'];            $qun1=$_post['question1'];       //db connection              $con=mysql_connect("localhost","root","");              mysql_select_db("dbname");            if($qun1!=0 && $test!=0)            {               foreach($qun1 $qunestion)              {               echo $question;   //this testing                  $query=mysql_query("delete test_question test_questions_id='$test' , question_id  in ('$question') " ) or die(mysql_error());             }           if($query)          {               echo "success";          }        else         {          echo "no";          }     }  }  ?> 

my code working if use not in in place of in not working..why?..if unchecked records should delete..i retrieve records database checked fields..

my html markup:

     <script>        function fun2(ts)        {          $.post("ajax2.php",{qs:ts},function(data)           {             document.getelementbyid('div1').innerhtml=data            })          }        </script>      <form action="somepage.php" method="post">       //dynamic selection test code      <select name="test" id="test" onchange="fun2(this.value);">          <option value="">select test</option> </select>        <div id="div1" > </div>     <input type="submit" name="delete" value="delete" >   </from> 

my ajax code:

      <?php          $qs=$_request['qs'];          mysql_connect("localhost","root","");         mysql_select_db("advancedge");         $sql=mysql_query("select question_id  test_question test_questions_id='$qs'");      if($sql)       {        while($rec=mysql_fetch_row($sql))        {          echo "<input type='checkbox' name='question1[]' value='$rec[0]' checked='checked' >";            }     }   ?> 

if understand correctly, want delete item unchecked? check if checkbox unchecked, have use javascript. php runs on server, not client side (you use ajax, recommend not this).

i recommend, delete whatever want on form submission, if don't know how that,i can tell if post html part up.

i recommend learn php course on internet, know standards , practices. (youtube or lynda.com)


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -