selected checkbox value stored in database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • palanidharma
    New Member
    • Feb 2008
    • 10

    selected checkbox value stored in database

    hi ,

    i am new to php.just i am writing checkbox coding. how to store the selected check box value in Mysql.
    [php]
    $sql=mysql_quer y("select * from $ttablename") or die(mysql_error ());

    while($row=mysq l_fetch_row($sq l))
    {
    echo"<tr>
    <td><input type='checkbox' name='arr[]'></td>
    <td >$row[0]</td>
    <td>$row[1]</td>
    <td>$row[2]</td>
    </tr>";
    }
    [/php]
    please reply me
    Last edited by ronverdonk; Feb 15 '08, 09:45 AM. Reason: code within tags
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    welcome to TSDN!

    In order to help you, show all code you have developed so far. The code you showed does not include a <form> with a submit statement.

    So let's see all of it and do not forget to include that code within the appropriate code tags!.. Please read the Posting Guidelines.

    Ronald

    Comment

    • palanidharma
      New Member
      • Feb 2008
      • 10

      #3
      Originally posted by ronverdonk
      welcome to TSDN!

      In order to help you, show all code you have developed so far. The code you showed does not include a <form> with a submit statement.

      So let's see all of it and do not forget to include that code within the appropriate code tags!.. Please read the Posting Guidelines.

      Ronald




      <?php
      include("conn.p hp");
      $sel= mysql_select_db ("sangoma");
      //include("functi on.php");

      ?>
      <div id="layout1">
      <center>
      <table border="0" cellpadding="1" cellspacing="1" >
      <form method='post' action='<?php $_SERVER[PHP_SELF] ?>' name='agentdisp '>
      <tr>
      <td align="right">C ampaign Name:</td><td>
      <?
      $tab= $_GET['tab'];
      $_SESSION['$t_tab']=$tab;
      $r = mysql_query("sh ow tables");
      echo "<select name=tablename value=\'\' size=1 onchange=\"relo ad(this.form)\" >";
      echo "<option value=''>Table Name</option>";
      while($res1 = mysql_fetch_row ($r)) {
      if($res1[0]==@$tab){
      echo "<option selected value='$tab'>$t ab</option>"."<BR>" ;
      }else{
      echo "<option value='$res1[0]'>$res1[0]</option>";}
      }
      echo "</select>";
      ?>
      </td>
      </tr>
      <tr><td colspan="2" align="center"> <input type="submit" name="submit" value="Submit" class="butt" /></td></tr>
      </form>
      </table>
      </center>


      <?
      $submit=$_POST['submit'];
      if($submit=='Su bmit')
      {

      //mysql_query("de lete from sangomatemp.tem p") or die(mysql_error ());

      $ttablename = $_POST{'tablena me'};




      /*echo"<table border=0 cellpading=0 cellspacing=0>" ;
      echo"<td>phone</td>";
      echo"<td></td>";
      echo"<td></td>";
      echo"<td></td>";
      echo"<td></td>";
      echo"<td></td>";
      echo"<td></td>";
      echo"<td></td>";
      echo"<td></td>";
      echo"<td>l</td></tr>";*/



      echo "<table border=1 align=center id='thetable'>
      <tr><td class='th'>Sele ct</td><td class='th'>SKU #</td><td class='th'>Desc ription</td><td class='th'>List Price with Customs</td></tr>";

      //$q="select phone from newtest where phone<>''";
      //$q1=mysql_query ($q) or die("could not connect".mysql_ error());


      echo $ttablename;

      $sql=mysql_quer y("select * from $ttablename") or die(mysql_error ());

      while($row=mysq l_fetch_row($sq l))
      {

      echo"<tr>
      <td><input type='checkbox' name='arr[]'></td>
      <td >$row[0]</td>
      <td>$row[1]</td>
      <td>$row[2]</td>


      </tr>";
      }


      echo "</table>";

      echo"<table border=0 cellspacing=0 cellspadding=0> ";

      echo"<input type='submit' name='submit' value='Submit' />";
      //echo "<tr><td><a href='sub_drive .php' target='_blank' >Next</a></td></tr></table>";

      }
      ?>

      </div>
      </DIV>
      </DIV>

      <script language="javas cript">
      function alternate(id){
      if(document.get ElementsByTagNa me){
      var table = document.getEle mentById(id);
      var rows = table.getElemen tsByTagName("tr ");
      for(i = 0; i < rows.length; i++){
      //manipulate rows
      if(i % 2 == 0){
      rows[i].className = "even";
      }else{
      rows[i].className = "odd";
      }
      }
      }
      }
      </script>
      </body>
      </html>

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Your second submit - and I cannot give a line number because the code is not within code tags - is not attached to a form so it will not get submitted.

        And for the second time: enclose any code within coding tags!. The way it looks does not invite many members to scan through it.

        Ronald

        Comment

        Working...