Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Add check box names to database table

$
0
0

I am trying desperately to add checkbox names to a table on my database, i've read loads of tutorials and haven't really gotten very far.

Here is my code

 <script language="JavaScript">
  function toggle(source) {
    checkboxes = document.getElementsByTagName('input');
    for(var i=0, n=checkboxes.length;i<n;i++) {
      checkboxes[i].checked = source.checked;
    }
  }
  </script>
  
 <?php
 $con=mysqli_connect("localhost","kslc_admin","password","kslc_cdg");
 // Check connection
 if (mysqli_connect_errno())
   {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }
 
 $result = mysqli_query($con,"SELECT DISTINCT DiscNo, Description FROM CDG ORDER BY DiscNo");
 echo "<td><input type=\"checkbox\" onClick=\"toggle(this)\" /> Toggle All<br/></td>";
 echo "<form action=\"post.php\" method=\"post \" />";
 echo "<table>
 <tr>
 <th>Tag</th>
 <th>Description</th>
 <th>DiscNo</th>
 <th>View Songs</th>
 </tr>";
 
 
 while($row = mysqli_fetch_array($result))
   {
   echo "<tr>"; 
   echo "<td><input type=\"checkbox\" name=". $row["DiscNo"] ."  id=\"checkbox\"></td>";
   echo "<td>" . $row['Description'] . "</td>";
   echo "<td>" . $row['DiscNo'] . "</td>";
   echo "<td>" . $row['TrackNo'] . "</td>";
   echo "<td><a href=\"tracks.php?DiscNo=" . $row["DiscNo"] . "\">View Tracks</a></td>";
   echo "</tr>";
   }
 echo "</table>";
 echo "<input type=\"submit\" name=\"submit\" value=\"Submit \" />";
 echo "</form>";
 
 
 mysqli_close($con);
 ?>

Now i don't know if this is even in the right direction but ive been trying to pass the checkbox names to post.php and somehow retrieve them and run a function to add to db table. Not sure how to achieve this or even if this is the correct way to go about it .. So far when i hit submit the URL looks like this 

http://mydomain.com/post.php?SF001=on&SF161=on&SF179=on&submit=Submit+

Where SF001, SF161 & SF179 are the correct checkbox names of selected checkboxes. So it is possible to retrieve these in post.php and somehow add them to database ?

 

 

 

Really appreciate any help .. Thanks


Viewing all articles
Browse latest Browse all 13200

Trending Articles