Thanks - sorry - I am at boarding school and the internet cuts off at 11 so I couldn't reply earlier...
Anyway - thankyou - I have incorporated the Delete.php and viewdevices.php together which is great but the query still doesn't work... here is the code:
<?php
session_start();
if (!isset($_SESSION['loggedin'])
|| $_SESSION['loggedin'] !== true) {
header('Location: login.php');
exit;
}
$self = $_SERVER['PHP_SELF'];
$x10_channel = $_POST['x10_channel'];
$device = $_POST['device'];
$conn=@mysql_connect( "localhost", "alexm", "rugby" )
or die( "Err:Conn" );
$db = @mysql_select_db( "rugby_project", $conn) or die( "Err:Db" );
if($_GET["cmd"]=="delete" & !empty($_GET["device"]))
{
$x10_channel = $_GET['x10_channel'];
$device = $_GET['device'];
$sql = "DELETE FROM devices WHERE device=$device, x10_channel=$x10_channel";
$result = @mysql_query($sql,$conn)
or die("Could not delete device");
if($result)
{
echo( "<table width=\"30%\" border=\"1\" align=\"center\" cellpadding=\"4\" cellspacing=\"1\" bordercolor=\"#000000\">
<tr bgcolor=\"#CCCCCC\">
<td colspan=\"2\"><font size=\"1\" face=\"Verdana\">
<center>$device on $x10_channel has been deleted</center></font></td></tr></table>" );
echo( "<center><p><font size=\"1\" face=\"Verdana\">
<a href=\"viewdevices.php\">Back</a> |
<a href=\"control.php\">Return to Control Panel</a> |
<a href=\"logout.php\">Log out<p></a>
</body></html>" );
}
}
else
{
$sql = "select device, x10_channel from devices order by x10_Channel";
$rs = @mysql_query( $sql,$conn);
$rows = mysql_num_rows($rs);
echo( "<table width=\"20%\" border=\"1\" align=\"center\" cellpadding=\"4\" cellspacing=\"1\" bordercolor=\"#000000\">
<tr bgcolor=\"#CCCCCC\">
<td colspan=\"3\"><font size=\"1\" face=\"Verdana\">
<center>Devices View</center></font></td></tr>" );
echo( "<tr><td><font size=\"1\" face=\"Verdana\"><strong>X10 Channel</td>" );
echo( "<td><font size=\"1\" face=\"Verdana\"><strong>Device</td>" );
echo( "<td><font size=\"1\" face=\"Verdana\"><i><center>Delete</td></tr>" );
if(mysql_num_rows($rs))
{
while( $row = mysql_fetch_array( $rs ) )
{
$x10_channel=$row["x10_channel"];
$device=$row["device"];
echo( "<tr><td>\n<font size=\"2\" face=\"Verdana\">" . $row["x10_channel"] . "</td>" );
echo( "<td><font size=\"2\" face=\"Verdana\">" . $row["device"] . "</td>" );
echo( "<td><font size=\"2\" face=\"Verdana\"><center><a href='$self?
cmd=delete&device=$device&x10_channel=$x10_channel'>x</a></td></tr>" );
}
echo( "</table><p><table width=\"20%\" border=\"1\" align=\"center\" cellpadding=\"4\" cellspacing=\"1\"
bordercolor=\"#000000\">
<tr bgcolor=\"#CCCCCC\">
<td colspan=\"2\"><font size=\"1\" face=\"Verdana\">
<center>There are $rows records in this table</center></font></td></tr></table>" );
echo( "<center><p><font size=\"1\" face=\"Verdana\">
<a href=\"control.php\">Return to Control Panel</a> |
<a href=\"logout.php\">Log out<p></a>
</body></html>" );
}
else
{
echo( "<table width=\"30%\" border=\"1\" align=\"center\" cellpadding=\"4\" cellspacing=\"1\" bordercolor=\"#000000\">
<tr bgcolor=\"#CCCCCC\">
<td colspan=\"2\"><font size=\"1\" face=\"Verdana\">
<center>This table has no records yet</center></font></td></tr></table>" );
}
}
?>
Where is it going wrong - I get the echo - Could not delete device
Also - if I want to replace the href line:
echo( "<td><font size=\"2\" face=\"Verdana\"><center><a href='$self?cmd=delete&device=$device&x10_channel=$x10_channel'>x</a></td></tr>" );
with a submit button, how do I do this so that the device and channel and posted? Would this work in replacement of the above line?:
echo( "<td><form action='$self' method=post><input type=hidden name=cmd value='delete'><input type=hidden name=device value='$device'><input type=hidden name=x10_channel value='$x10_channel'><input type=submit name=delete value='x'>" );
And with this submit button what code do I need to put in place of the delete query itself (something like:?)
if(isset($_POST['delete'])) {
$x10_channel = $_GET['x10_channel'];
$device = $_GET['device'];
$sql = "DELETE FROM devices WHERE device=$device, x10_channel=$x10_channel";
$result = @mysql_query($sql,$conn)
or die("Could not delete device");
if($result)
{
echo( "<table width=\"30%\" border=\"1\" align=\"center\" cellpadding=\"4\" cellspacing=\"1\" bordercolor=\"#000000\">
<tr bgcolor=\"#CCCCCC\">
<td colspan=\"2\"><font size=\"1\" face=\"Verdana\">
<center>$device on $x10_channel has been deleted</center></font></td></tr></table>" );
I have tried all this but none of it works properly - Thanks very much again in advance for your help!
As for the delete check boxes this looks great but I can't even get the script to work at all because I do not understand the $val: (it comes up in debugging via command prompt as unexpected T_variable here is the script using your suggestion (I think - it must be wrong somewhere????!!!)
<?php
session_start();
if (!isset($_SESSION['loggedin'])
|| $_SESSION['loggedin'] !== true) {
header('Location: login.php');
exit;
}
$self = $_SERVER['PHP_SELF'];
$x10_channel = $_POST['x10_channel'];
$device = $_POST['device'];
$conn=@mysql_connect( "localhost", "alexm", "rugby" )
or die( "Err:Conn" );
$db = @mysql_select_db( "rugby_project", $conn) or die( "Err:Db" );
if (isset($_POST['delete']) && isset($_POST['delboy'])) {
$delstring = '';
foreach ($_POST['delboy'] as $val) {
$delstring .= "'" $val . "',";
}
$delstring = rtrim($delstring, ',');
$delquery = "DELETE FROM Devices WHERE device IN (" . $delstring . ")";
$result = mysql_query($delquery) or die("Could not delete device");
if($result)
{
echo( "<table width=\"30%\" border=\"1\" align=\"center\" cellpadding=\"4\" cellspacing=\"1\" bordercolor=\"#000000\">
<tr bgcolor=\"#CCCCCC\">
<td colspan=\"2\"><font size=\"1\" face=\"Verdana\">
<center>$device on $x10_channel has been deleted</center></font></td></tr></table>" );
echo( "<center><p><font size=\"1\" face=\"Verdana\">
<a href=\"viewdevices.php\">Back</a> |
<a href=\"control.php\">Return to Control Panel</a> |
<a href=\"logout.php\">Log out<p></a>
</body></html>" );
}
}
else
{
$sql = "select device, x10_channel from devices order by x10_Channel";
$rs = @mysql_query( $sql,$conn);
$rows = mysql_num_rows($rs);
echo( "<table width=\"20%\" border=\"1\" align=\"center\" cellpadding=\"4\" cellspacing=\"1\" bordercolor=\"#000000\">
<tr bgcolor=\"#CCCCCC\">
<td colspan=\"3\"><font size=\"1\" face=\"Verdana\">
<center>Devices View</center></font></td></tr>" );
echo( "<tr><td><font size=\"1\" face=\"Verdana\"><strong>X10 Channel</td>" );
echo( "<td><font size=\"1\" face=\"Verdana\"><strong>Device</td>" );
echo( "<td><font size=\"1\" face=\"Verdana\"><i><center>Delete</td></tr>" );
if(mysql_num_rows($rs))
{
echo '<form name="delform" method="post" action="$self">';
while( $row = mysql_fetch_array( $rs ) ){
$x10_channel=$row["x10_channel"];
$device=$row["device"];
echo '<tr><td>\n<font size="2" face="Verdana">' . $x10_channel . '</td>';
echo '<td><font size="2" face="Verdana">' . $device . '</td>';
echo '<td><input type="checkbox" name="delboy[]" value="' . $device . '" /></td></tr>';
}
echo '<tr><td colspan="3"><input type="submit" name="delete" value="delete" /><input type="reset" name="reset" value="reset" /></td></tr></form>';
echo '</table><p><table width="20%" border="1" align="center" cellpadding="4" cellspacing="1" bordercolor="#000000">
<tr bgcolor="#CCCCCC"><td colspan="2"><font size="1" face="Verdana"><center>There are $rows records in this table</center></font></td></tr></table>';
echo( "<center><p><font size=\"1\" face=\"Verdana\">
<a href=\"control.php\">Return to Control Panel</a> |
<a href=\"logout.php\">Log out<p></a>
</body></html>" );
}
else
{
echo( "<table width=\"30%\" border=\"1\" align=\"center\" cellpadding=\"4\" cellspacing=\"1\" bordercolor=\"#000000\">
<tr bgcolor=\"#CCCCCC\">
<td colspan=\"2\"><font size=\"1\" face=\"Verdana\">
<center>This table has no records yet</center></font></td></tr></table>" );
}
}
?>