•
•
•
•
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
![]() |
•
•
Join Date: Feb 2008
Posts: 37
Reputation:
Rep Power: 1
Solved Threads: 0
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>
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>
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,057
Reputation:
Rep Power: 8
Solved Threads: 229
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*
*PM asking for help will be ignored*
•
•
Join Date: Feb 2008
Posts: 37
Reputation:
Rep Power: 1
Solved Threads: 0
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
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
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,057
Reputation:
Rep Power: 8
Solved Threads: 229
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*
*PM asking for help will be ignored*
•
•
Join Date: Feb 2008
Posts: 37
Reputation:
Rep Power: 1
Solved Threads: 0
•
•
•
•
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
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,057
Reputation:
Rep Power: 8
Solved Threads: 229
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 ?
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*
*PM asking for help will be ignored*
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,057
Reputation:
Rep Power: 8
Solved Threads: 229
php Syntax (Toggle Plain Text)
<?php $conn=mysql_connect("localhost","root"); mysql_select_db("test"); $operation=$_POST['operation']; $id=$_POST['id']; if(isset($_POST['submit'])) { $team=implode(",",$_POST['team']); $name=$_POST['name']; $q="insert into table1 (name, team) values ('$name','$team')"; mysql_query($q); } if($operation=="delete"){ $q="delete from table1 where counter='$id'"; mysql_query($q); } if(isset($_POST['update'])){ $name=$_POST['name']; $team=implode(",",$_POST['team']); $q="update table1 set name='$name', team='$team' where counter='$id'"; mysql_query($q); } ?> <html> <body> <form method="post" name="insertform" action="checkbox1.php"> Enter name: <input type="text" name="name" /><br /> <input type="checkbox" name="team[]" value="AG">Argentina <br /> <input type="checkbox" name="team[]" value="BR">Brazil <br /> <input type="checkbox" name="team[]" value="GE">Germany <br /> <input type="checkbox" name="team[]" value="EN">England <br /> <input type="submit" name="submit" value="submit"> </form> <hr> <form method="post" name="editform" action="checkbox1.php"> <input type="hidden" name="id"> <input type="hidden" name="operation"> <?php $q="select counter,name from table1"; $result=mysql_query($q); while($row=mysql_fetch_array($result)){ $name=$row['name']; $id=$row['counter']; 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 />"; } ?> </form> <hr> <?php if($operation=="edit") { $id=$_POST['id']; ?> <form method="post" name="updateform" action="checkbox1.php"> <input type="hidden" name="id" value="<?php echo $id; ?>"> <?php $q="select * from table1 where counter='$id'"; $result=mysql_query($q); $row=mysql_fetch_array($result); $name=$row['name']; $team=$row['team']; $teamarray=explode(",",$team); echo "<input type=\"text\" name=\"name\" value=\"$name\"><br />"; ?> <input type="checkbox" name="team[]" value="AG" <?php if(in_array("AG",$teamarray)){ echo "checked"; } ?>>Argentina <br /> <input type="checkbox" name="team[]" value="BR" <?php if(in_array("BR",$teamarray)){ echo "checked"; } ?>>Brazil <br /> <input type="checkbox" name="team[]" value="GE" <?php if(in_array("GE",$teamarray)){ echo "checked"; } ?>>Germany <br /> <input type="checkbox" name="team[]" value="EN" <?php if(in_array("EN",$teamarray)){ echo "checked"; } ?>>England <br /> <input type="submit" name="update" value="update"> <?php } ?> </body> </html>
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*
*PM asking for help will be ignored*
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
- 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