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 375,193 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 2,200 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
Views: 4983 | Replies: 66
Reply
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

  #31  
Feb 13th, 2008
Hi nav, I have already made a dynamic table where the checkbox values are stored in db table and printed on the screen see code below..

what i want to do is edit/delete the database values in a php form. so when it can change the data in the db and countries can be added or deleted on a form rather than making changes in MYPHPADMIN.

Cheers

<form id="form1" name="form1" method="post" action="page2.php">
<?php
$sql = 'SELECT * From Countries';

$con = mysql_connect("localhost","root","mariapa") or die;


$result = mysql_db_query(talk21, $sql);



while ($rec = mysql_fetch_array($result))
{
print "\n<input type='checkbox' name=Countries[]' value='".$rec['id']."' > ".$rec['Country']." </input>";
}

?><br />
<input type="submit" name="Submit" value="Register" />
</label>
</form>
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,057
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 229
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: inserting checkbox values in mysql +PHP

  #32  
Feb 13th, 2008
The second script lists all the teams in the table. Select the ones which you want to delete and click on submit! It ll delete all those teams from the table. I don't know how you can edit and what you mean by edit !
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
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

  #33  
Feb 14th, 2008
By edit I mean to an existing record that has been added to the database e.g

if i have a record which i want to change

id| name|last_name|countries
1 priya rai BR, FR



Say i just wanted to change the record name from priya to rianah without changing anything else

id| name|last_name|countries
1 rianah rai BR, FR
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,057
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 229
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: inserting checkbox values in mysql +PHP

  #34  
Feb 14th, 2008
While listing the records, show previous name in a textbox and when submit is clicked, update it ?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
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

  #35  
Feb 14th, 2008
Originally Posted by nav33n View Post
While listing the records, show previous name in a textbox and when submit is clicked, update it ?


yes thats right i will have record set displaying all the user informtion on one big table. user can look at this table and and user can select onclick or by checking a checkbox and the record that is selected like e.g 2 kelle bria BR can be changed or deleted on another page.

id| name|last_name|countries
1 priya rai BR, FR
2 kelle bria BR
3 adam kel GB
Reply With Quote  
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

  #36  
Feb 15th, 2008
While listing the records, show previous name in a textbox and when submit is clicked, update it ?


Naveen I am wondering if its possible to edit in the record set by checkbox and redirect user to change records like a textbox field?
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,057
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 229
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: inserting checkbox values in mysql +PHP

  #37  
Feb 15th, 2008
Hi, Sorry. I didn't get it. Could you please re-explain the whole thing to me ? Is it like this.
You have a textbox to enter the name, list of checkboxes to select the country and a submit button. You can add records to the table from this screen. You need another screen where you can edit the records in the table ? (change the name and checkbox values ?) Is this what you are asking ?
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
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

  #38  
Feb 15th, 2008
Yes exactly thats what i mean.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,057
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 229
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: inserting checkbox values in mysql +PHP

  #39  
Feb 15th, 2008
  1. <?php
  2. $conn=mysql_connect("localhost","root");
  3. mysql_select_db("test");
  4. $operation=$_POST['operation'];
  5. $id=$_POST['id'];
  6. if(isset($_POST['submit'])) {
  7. $team=implode(",",$_POST['team']);
  8. $name=$_POST['name'];
  9. $q="insert into table1 (name, team) values ('$name','$team')";
  10. mysql_query($q);
  11. }
  12. if($operation=="delete"){
  13. $q="delete from table1 where counter='$id'";
  14. mysql_query($q);
  15. }
  16. if(isset($_POST['update'])){
  17. $name=$_POST['name'];
  18. $team=implode(",",$_POST['team']);
  19. $q="update table1 set name='$name', team='$team' where counter='$id'";
  20. mysql_query($q);
  21. }
  22. ?>
  23. <html>
  24. <body>
  25. <form method="post" name="insertform" action="checkbox1.php">
  26. Enter name: <input type="text" name="name" /><br />
  27. <input type="checkbox" name="team[]" value="AG">Argentina <br />
  28. <input type="checkbox" name="team[]" value="BR">Brazil <br />
  29. <input type="checkbox" name="team[]" value="GE">Germany <br />
  30. <input type="checkbox" name="team[]" value="EN">England <br />
  31. <input type="submit" name="submit" value="submit">
  32. </form>
  33. <hr>
  34. <form method="post" name="editform" action="checkbox1.php">
  35. <input type="hidden" name="id">
  36. <input type="hidden" name="operation">
  37. <?php
  38. $q="select counter,name from table1";
  39. $result=mysql_query($q);
  40. while($row=mysql_fetch_array($result)){
  41. $name=$row['name'];
  42. $id=$row['counter'];
  43. echo $name ."<input type=\"button\" name=\"edit\" value=\"edit\" onclick=\"javascript: document.editform.operation.value='edit';document.editform.id.value='$id';document.editform.submit();\"><input type=\"button\" name=\"delete\" value=\"Delete\" onclick=\"javascript: document.editform.operation.value='delete';document.editform.id.value='$id'; document.editform.submit();\"><br />";
  44. }
  45. ?>
  46. </form>
  47. <hr>
  48. <?php
  49. if($operation=="edit") {
  50. $id=$_POST['id'];
  51. ?>
  52. <form method="post" name="updateform" action="checkbox1.php">
  53. <input type="hidden" name="id" value="<?php echo $id; ?>">
  54. <?php
  55. $q="select * from table1 where counter='$id'";
  56. $result=mysql_query($q);
  57. $row=mysql_fetch_array($result);
  58. $name=$row['name'];
  59. $team=$row['team'];
  60. $teamarray=explode(",",$team);
  61. echo "<input type=\"text\" name=\"name\" value=\"$name\"><br />";
  62. ?>
  63. <input type="checkbox" name="team[]" value="AG" <?php if(in_array("AG",$teamarray)){ echo "checked"; } ?>>Argentina <br />
  64. <input type="checkbox" name="team[]" value="BR" <?php if(in_array("BR",$teamarray)){ echo "checked"; } ?>>Brazil <br />
  65. <input type="checkbox" name="team[]" value="GE" <?php if(in_array("GE",$teamarray)){ echo "checked"; } ?>>Germany <br />
  66. <input type="checkbox" name="team[]" value="EN" <?php if(in_array("EN",$teamarray)){ echo "checked"; } ?>>England <br />
  67. <input type="submit" name="update" value="update">
  68. <?php
  69. }
  70. ?>
  71. </body>
  72. </html>
Well, Here is the code. The code is lil confusing (and untidy) but I am in no mood to write any better code. I am doing everything in 1 page. You can insert, edit and delete a record. Hope this will fix your problem.

Cheers,
Naveen
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Oct 2007
Posts: 6
Reputation: amin007 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
amin007 amin007 is offline Offline
Newbie Poster

Solution Re: inserting checkbox values in mysql +PHP

  #40  
Feb 15th, 2008
if(isset($_POST['team']))
{ 
	foreach($_POST['team'] as $value)
	{
	$insert="INSERT INTO team('team')VALUES ('$value')";
	echo "$insert<br>";
	}
}

are you want to do like this???
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 2:05 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC