Thanks. I tried to follow your good suggestions, and hope I got it right. I still got the same problem: the page reloads when I hit the delete button after checking the entry I want to delete, but nothing happens.
Can the problem be the in the first part of the delete process (marked with ****)? Am I naming things wrongly?
PS! Sorry for the ugly code last time...
-Falkenberg
<?php
$connect = mysql_connect("mysql.speech.kth.se", "musicrefuser", "********") or die(mysql_error());
$select_db = mysql_select_db("musicref") or die(mysql_error());
$dbcnx = @mysql_connect("mysql.speech.kth.se", "musicrefuser", "********") or die(mysql_error());
$query = mysql_query("SELECT * from copy;") or die(mysql_error());
if (!$dbcnx)
{
echo( "<p>Unable to connect.</p>");
exit();
}
//select the references database
if (! @mysql_select_db("musicref", $dbcnx) )
{
echo( "<p>Unable lo locate the references database at this time.</p>" );
exit();
}
// If a conference has been submitted
if ($submit == "SUBMIT")
{
//Insert into the displayed database
$sql = "INSERT INTO `copy` SET
`datefrom`='$datefrom',
`dateto`='$dateto',
`abbrtitle`='$abbrtitle',
`fulltitle`='$fulltitle',
`link`='$link',
`host`='$host',
`city`='$city',
`country`='$country',
`deadline`='$deadline',
`comment`='$comment',
`submitby`='$submitby',
`type`='$type'";
//Control for error messages from sql-database
if (@mysql_query($sql))
{
echo ("<p>The conference is added</p>");
}
else
{
echo ("<p>Error adding the conference: " .
mysql_error());
}
}
//************************
//Delete rows from table part I
if (isset($_post['DELETE']))
{
?>
Entries have been deleted<br><br>
<?php
while (@list($key, $value) = each($_post['ID']))
{
$queryd = "delete from `copy` where `ID` = $value";
$resultd = mysql_query($queryd) or die(mysql_error());
}
?>
<form method="post" action="<?$PHP_SELF?>">
<?php
//delete rows part I pauses
//to delete rows, the following request must be done 2 times
//Request content and sort by the date
$result = @mysql_query("SELECT * FROM `copy` ORDER BY `datefrom` ASC") or die(mysql_error());
if (!$result)
{
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
//Display the name of the each entry in a paragraph
while ( $row = mysql_fetch_array($result) or die(mysql_error()) )
{
$refid = $refid + 1;
$ID = $row["ID"];
$color = changeColor($color);
echo ("<div class=\"partreference\" id='ref" . $refid . "short'> <table align=\"center\" class=\"first\">");
echo ("<tr bgcolor='$color'>" .
"<td class=\"abbrtitle\"> <a onclick=\"toggleDesc('$refid'); return false;\">" . $row["abbrtitle"] . "</a></td>" .
"<td class=\"fulltitle\">" . $row["fulltitle"] . " </td>" .
"<td class=\"type\">" . $row["type"] . "</td>" .
"<td class=\"datefrom\">" . $row["datefrom"] . "</td>" .
"<td class=\"link\"><a href=\"http://" .$row["link"] . "\">Webpage</a></td>" .
"<td><input type=\"checkbox\" name=\"ID\" VALUE=\"".$row["ID"]."\"></td>" .
"</tr>" . "\n");
echo ("</table> </div>");
}
?>
<input type="submit" value="DELETE" name="DELETE"></form>
<?php
//Delete rows from table part II
}
else
{
?>
<form method="post" action="<?$PHP_SELF?>">
<?php
//Delete rows part II pauses
//This is the second request...
//Request content and sort by the date
$result = @mysql_query("SELECT * FROM `copy` ORDER BY `datefrom` ASC") or die(mysql_error());
if (!$result)
{
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
//Display the name of the each entry in a paragraph
while ( $row = mysql_fetch_array($result) )
{
$refid = $refid + 1;
$ID = $row["ID"];
$color = changeColor($color);
echo ("<div class=\"partreference\" id='ref" . $refid . "short'> <table align=\"center\" class=\"first\">");
echo ("<tr bgcolor='$color'>" .
"<td class=\"abbrtitle\"> <a onclick=\"toggleDesc('$refid'); return false;\">" . $row["abbrtitle"] . "</a></td>" .
"<td class=\"fulltitle\">" . $row["fulltitle"] . " </td>" .
"<td class=\"type\">" . $row["type"] . "</td>" .
"<td class=\"datefrom\">" . $row["datefrom"] . "</td>" .
"<td class=\"link\"><a href=\"http://" .$row["link"] . "\">Webpage</a></td>" .
"<td><input type=\"checkbox\" name=\"ID\" VALUE=\"".$row["ID"]."\">
</td>" .
"</tr>" . "\n");
echo ("</table> </div>");
}
?>
<input type="submit" value="DELETE" name="DELETE">
</form>
<?php
}
?>
<?php
//form for adding conferences:
?>
<form name="newRef" method="post" action="<?$PHP_SELF?>">
<table class="form" align="center">
<tr>
<td class="head1" rowspan="3">Dates<br>
(yymmdd)</td>
<td class="head2">
<div align="left">From</div>
</td>
<td class="head1">
<input type="text" name="datefrom">
</td>
</tr>
</table>
<input type="submit" name="submit" value="SUBMIT"></form>