Originally Posted by
nav33n
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>