Hi, I'm new to PHP and am stumbling on this point - I would really appreciate some help- I can view my records fine. When I click submit next to a record it does not work. I want to be able to click edit and then be taken to a form with the initial values which I can edit and submit. Thanks in advance.
<html><head><title>View Devices</title></head>
<body>
<?php
session_start();
if (!isset($_SESSION['user'])
|| $_SESSION['user'] !== true)
{
header('Location: login.php');
exit;
}
$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>Your $val 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);
$self = $_SERVER['PHP_SELF'];
$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><font size="2" face="Verdana">' . $x10_channel . '</td>';
echo '<td><font size="2" face="Verdana">' . $device . '</td>';
echo '<td><center><input type="checkbox" name="delboy[]" value="' . $device . '" /></td></tr>';
}
echo '<tr><td colspan="3"><center><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' <p><font size="1" face="Verdana"><center>
<a href="javascript:history.go(-1)">Return to Control Panel</a> |
<a href="logout.php">Log out</a>
</body></html> ';
}
else
{
echo( "<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>This table has no records yet</center></font></td></tr></table>" );
}
}
?>