•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 423,538 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 4,292 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: 6113 | Replies: 66
![]() |
•
•
Join Date: Feb 2008
Posts: 37
Reputation:
Rep Power: 1
Solved Threads: 0
•
•
•
•
As I told you already, If you want to 'update' checkboxes, ie., If you want to delete a checkbox, you have to delete all the checkboxes and then insert only those checkboxes which are checked. I don't know how you can 'add' checkboxes.
I think we are still confused, I don’t want to add a checkbox like that at all.
I have 1 table called team, with 2 columns.
Id team
1 BR
2 GB
3 FR
the only purpose this table serves is to be printed on the form dynamically instead of hard coding the checkboxes.
php Syntax (Toggle Plain Text)
$result = mysql_db_query(team, $sql); while ($rec = mysql_fetch_array($result)) { print "\n<input type='checkbox' name=team[]' value='".$rec['id']."' > ".$rec['team']." </input>";
So all I want to do is update what’s on the team table, so the form can dynamically show what’s on the table, I know I can just add the values on phpmyadmin but I want to make a admin page so admin can change what appears on the forms.
id team
1 BR
2 GB
3 FR
cheers naveen
Last edited by peter_budo : Feb 22nd, 2008 at 7:41 am. Reason: Please use [code] tags for even partial code
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
Thats very simple.
1. To add a team: Have a textbox where the user can enter a team and submit it.
2. To update/delete a team, list all the teams as you are doing here. By default, check all the checkboxes. The user can remove a team by clearing the checkbox and click on submit. When the user clicks on submit, remove all the records from team and insert only those which are checked. So, in the end, the table will have only those teams which were checked. I hope this is what you are saying.
1. To add a team: Have a textbox where the user can enter a team and submit it.
2. To update/delete a team, list all the teams as you are doing here. By default, check all the checkboxes. The user can remove a team by clearing the checkbox and click on submit. When the user clicks on submit, remove all the records from team and insert only those which are checked. So, in the end, the table will have only those teams which were checked. I hope this is what you are saying.
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*
*PM asking for help will be ignored*
•
•
Join Date: Feb 2008
Posts: 37
Reputation:
Rep Power: 1
Solved Threads: 0
•
•
•
•
Thats very simple.
1. To add a team: Have a textbox where the user can enter a team and submit it.
2. To update/delete a team, list all the teams as you are doing here. By default, check all the checkboxes. The user can remove a team by clearing the checkbox and click on submit. When the user clicks on submit, remove all the records from team and insert only those which are checked. So, in the end, the table will have only those teams which were checked. I hope this is what you are saying.
Ok, i tried this but I have an error on deleteting and updating, when user submits, it should delete all the unset checkboxes.
php Syntax (Toggle Plain Text)
<form id="form1" name="form1" method="post" action="result.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'])){ } if(unset($_GET['id'])) { $q="delete from team where team[]='$id'"; mysql_query($q); } ?> <input type="submit" name="Submit" value="Register" /> </label> </form>
Last edited by peter_budo : Feb 22nd, 2008 at 7:42 am. Reason: Please use [code] tags
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
That wont work because it wouldn't know what are the unset fields. Why don't u delete all the records and insert only those which are checked ?
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*
*PM asking for help will be ignored*
•
•
Join Date: Feb 2008
Posts: 37
Reputation:
Rep Power: 1
Solved Threads: 0
•
•
•
•
Thats very simple.
1. To add a team: Have a textbox where the user can enter a team and submit it.
2. To update/delete a team, list all the teams as you are doing here. By default, check all the checkboxes. The user can remove a team by clearing the checkbox and click on submit. When the user clicks on submit, remove all the records from team and insert only those which are checked. So, in the end, the table will have only those teams which were checked. I hope this is what you are saying.
•
•
•
•
That wont work because it wouldn't know what are the unset fields. Why don't u delete all the records and insert only those which are checked ?
This is as close as i come to what you have mentioned above, the code is error free but does not do anything. I am looping trough the checkboxes and trying to remove the ckecked checkboxes.
php Syntax (Toggle Plain Text)
<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['delete'])){ } $id = $_GET['id']; (!isset($_GET['id'])) { foreach($_GET['team'] as $value) { $delete = "DELETE FROM team WHERE id='$id' "; mysql_query($delete); mysql_close(); echo "Entry deleted"; ?> <input type="submit" name="Submit" value="submit" /> </label> </form>
Last edited by peter_budo : Feb 22nd, 2008 at 7:43 am. Reason: Please use [code] tags
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
No. I didn't mean this. Well, Imagine I have 5 records in my table which resemble the checkboxes like above.
I dont think I can think more than that.
id | team 1 | team1 2 | team2 3 | team3 4 | team4 5 | team5
php Syntax (Toggle Plain Text)
if(isset($_POST['submit'])){ $q="delete from team"; //delete all the teams mysql_query($q); foreach($_POST['team'] as $value){ $q="insert into table (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>";
I dont think I can think more than that. Last edited by nav33n : Feb 21st, 2008 at 11:55 am.
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*
*PM asking for help will be ignored*
•
•
Join Date: Feb 2008
Posts: 37
Reputation:
Rep Power: 1
Solved Threads: 0
There are errors in the code,
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
i tried even diffrent ways, to delete,
Isnt there an easir way to delete a checkbox??
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
php Syntax (Toggle Plain Text)
<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>";
i tried even diffrent ways, to delete,
php Syntax (Toggle Plain Text)
if(isset($_POST['delete'])){ } $id = $_GET['id']; (!isset($_GET['id'])) foreach($_GET['team'] as $value) { $team = $_REQUEST['team']; //'countries' is the name of the combobox for ($i=0; $i<sizeof($team); $i++) { if (isset($team[$i])) { $delete = "DELETE FROM team WHERE id='$id' "; mysql_query($delete); mysql_close();
Isnt there an easir way to delete a checkbox??
Last edited by peter_budo : Feb 22nd, 2008 at 7:44 am. Reason: Please use [code] tags
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
•
•
•
•
Isnt there an easir way to delete a checkbox??
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*
*PM asking for help will be ignored*
•
•
Join Date: Feb 2008
Posts: 37
Reputation:
Rep Power: 1
Solved Threads: 0
For Now, all i want to do is delete a checkbox, in mysql
this code u looks good but has has errors.
$delete = "DELETE FROM team WHERE id='$id' "; mysql_query($delete); mysql_close();
this code u looks good but has has errors.
php Syntax (Toggle Plain Text)
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>";
Last edited by peter_budo : Feb 22nd, 2008 at 8:00 am. Reason: Please use [code] tags
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
What error exactly ?
Dude, list all the teams. Let the user select the checkboxes and then click on delete. Go back to page 1 and check the example I have given. Do the same, but use delete query. And instead of passing the team name as value, pass the id.
Dude, list all the teams. Let the user select the checkboxes and then click on delete. Go back to page 1 and check the example I have given. Do the same, but use delete query. And instead of passing the team name as value, pass the id.
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*
*PM asking for help will be ignored*
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Variable passed to each() is not an array (PHP)
- How to delete using checkboxes (PHP)
- Storing dynamic form values in Arrays for display & insert (PHP)
Other Threads in the PHP Forum
- Previous Thread: problem in deleting
- Next Thread: Cookies problem - not working



Linear Mode