User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,800 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,910 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting

inserting checkbox values in mysql +PHP

Join Date: Feb 2008
Posts: 37
Reputation: asadalim1 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
asadalim1 asadalim1 is offline Offline
Light Poster

Re: inserting checkbox values in mysql +PHP

  #61  
Feb 22nd, 2008
[quote=nav33n;542446]What error exactly ?

here are the errors,
Warning: Invalid argument supplied for foreach() in C:\wamp\www\dynamic\edit.php on line 16

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\dynamic\edit.php on line 25


<form id="form1" name="form1" method="post" action="edit.php">
   
   team: <input type="text" name="team" /><br />
    <br>
        <?php
    $sql = 'SELECT * From team';
    $con = mysql_connect("localhost","root","talk21") or die;
    $result = mysql_db_query(lastr, $sql); 
       while ($rec = mysql_fetch_array($result)) 
    {
       print "\n<input type='checkbox'  name=team[]' value='".$rec['id']."'checked> ".$rec['team']." </input>"; 
 }
 if(isset($_POST['submit'])){
  $q="delete from team"; //delete all the teams
  mysql_query($q);
  foreach($_POST['team'] as $value){
    $q="insert into team (team) values ('$value')";
mysql_query($q); //so by the end, the table will have records which were checked and all the records which were unchecked will be removed.
 }
}
//I list these teams in my form. 
$q="select id,team from table";
$res=mysql_query($q);
echo "<form method='post' action='check.php'>";
while($row=mysql_fetch_array($res)){
  echo "<input type='checkbox' name='team[]' value='$id' checked>".$team."<br />"; //this will list all the teams in the database
}
echo "<input type='submit' name='submit' value='submit'>";
echo "</form>";
	
Reply With Quote  
All times are GMT -4. The time now is 7:30 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC