•
•
•
•
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,562 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 3,639 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: 6117 | Replies: 66
![]() |
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
•
•
•
•
are you want to do like this???if(isset($_POST['team'])) { foreach($_POST['team'] as $value) { $insert="INSERT INTO team('team')VALUES ('$value')"; echo "$insert<br>"; } }
Last edited by nav33n : Feb 15th, 2008 at 1:25 pm.
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,098
Reputation:
Rep Power: 8
Solved Threads: 240
the query isn't returning any resultset. Check your query, execute it in phpmyadmin/mysql and see if it returns any value.
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
•
•
•
•
the query isn't returning any resultset. Check your query, execute it in phpmyadmin/mysql and see if it returns any value.
I have managed to run the code, thanks for the tip
, I executed the query in phpadmin and from there it was obvious I had counter missing in the table.Now the problem I have is I cant add anything to the table or edit or delete. The input box name is there and the check boxes are there but when I submit nothing is added. The same goes for edit and delete when clicked the page checkbox1.php is loaded with no effect or change.
The table in mysql is as follows
Table1
Id int Not null auto_increment
name varchar 30 Not null
team varchar 30 Not null
Counter varchar 30 Not null
<?php
$con = mysql_connect("localhost","root","talk21") or die;
mysql_select_db("talk21");
$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);
}
?>
This is the processing page checkbox1.php
<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
$con = mysql_connect("localhost","root","talk21") or die;
mysql_select_db("talk21");
$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
$con = mysql_connect("localhost","root","talk21") or die;
mysql_select_db("talk21");
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>
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
Again, print out all your queries. Check if they insert/update and delete the record. It worked fine when I wrote the code. I don't know where you have misplaced something.
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
•
•
•
•
the query isn't returning any resultset. Check your query, execute it in phpmyadmin/mysql and see if it returns any value.
•
•
•
•
Again, print out all your queries. Check if they insert/update and delete the record. It worked fine when I wrote the code. I don't know where you have misplaced something.
Hi naveen, the whole process is working now, but when you update/delete it affects all the records you have submitted to the database e.g. if you have 10 countries and you wanted to edit only 1, it changes all. Also I wanted to display the records in a table and onclick just change the selected record.
I am populating the checkbox from a database and printing them on the form like below. I want a form to basically edit the values like in an admin section.
I don’t require filling in the checkbox, because only users will be doing that process, I want to update the existing checkbox values or add new checkbox.
select Countries::
<?php
$sql = 'SELECT * From Countries';
$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=Countries[]' value='".$rec['id']."' > ".$rec['country']." </input>";
}
?>
thanx for the help.
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
•
•
•
•
Hi naveen, the whole process is working now, but when you update/delete it affects all the records you have submitted to the database e.g. if you have 10 countries and you wanted to edit only 1, it changes all.
Are you updating the table depending on the unique key ? If you try updating the table like,
update table1 set col1='value1', col2='value2'"; , it will update all the records. •
•
•
•
I don’t require filling in the checkbox, because only users will be doing that process, I want to update the existing checkbox values or add new 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
•
•
•
•
Are you updating the table depending on the unique key ? If you try updating the table like,update table1 set col1='value1', col2='value2'";, it will update all the records.
I still don't understand the flow of your program.
FORM
user can view form,there are a few textboxes and a few checkboxes and listboxes.
the data in the listboxes and checkboxes are populated from the database and printed on the form.
e.g print "\n<input type='checkbox' name=Countries[]' value='".$rec['id']."' > ".$rec['Country']." </input>";
what i want do:
update checkboxes and listboxes. update team checkboxes values
1.edit teams
2. add/delete
so the form can be updated.
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
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.
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