The below was working okay, except for the fact that the entries weren't ordered, so I created a new column called position to order the entries. After doing this and editing the PHP to follow suit, it decided to stop working for some reason though, it will add people, and delete them, but when you choose to edit and announces
Warning: 0 is not a MySQL result index in ../../../xxx.php on line 98
<?php
include ("connect.inc");
$cadet = "<img src = http://www.file.co.uk/images/cadet.gif>";
$ensign = "<img src = http://www.file.co.uk/images/ensign.gif>";
== all other files are declared here ==
if ($submit) {
// here if no ID then adding else we're editing
if ($id) {
$sql = "UPDATE employees SET first='$first',last='$last',zone_name='$zone_name',rank='$rank',position='$position' WHERE id=$id";
} else {
$sql = "INSERT INTO employees (first,last,zone_name,rank,position) VALUES ('$first','$last','$zone_name','$rank','$position')";
}
// run SQL against the DB
$result = mysql_query($sql);
echo "Roster updated!<p>";
} elseif ($delete) {
// delete a record
$sql = "DELETE FROM employees WHERE id=$id";
$result = mysql_query($sql);
echo "$sql Record deleted!<p>";
} else {
// this part happens if we don't press submit
if (!$id) {
// print the list if there is not editing
$result = mysql_query("SELECT * FROM employees",$db);
while ($myrow = mysql_fetch_array($result)) {
printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF, $myrow["id"], $myrow["first"], $myrow["last"]);
printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["id"]);
}
}
?>
<P>
<a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>
<P>
<?php
if ($id) {
// editing so select a record
$sql = "SELECT * FROM employees ORDER BY position WHERE id=$id";
$result = mysql_query($sql);
=ERROR= $myrow = mysql_fetch_array($result); =ERROR=
$id = $myrow["id"];
$first = $myrow["first"];
$last = $myrow["last"];
$zone_name = $myrow["zone_name"];
$rank = $myrow["rank"];
$position = $myrow["position"];
// print the id for editing
?>
<input type=hidden name="id <?php echo $id ?>">
<?php
}
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<font color="white">
First name:<input type="Text" name="first" value="<?php echo $first ?>"><br>
Last name:<input type="Text" name="last" value="<?php echo $last ?>"><br>
Zone name:<input type="Text" name="zone_name" value="<?php echo $zone_name ?>"><br>
Position:<input type="Text" name="position" value="<?php echo $position ?>"><br>
Rank:<select name="rank">
<option value="<?php echo $cadet ?>">Cadet
<option value="<?php echo $ensign ?>">Ensign
<option value="<?php echo $fo ?>">Flight Officer
<option value="<?php echo $sfo ?>">Senior Flight Officer
<option value="<?php echo $lt2nd ?>">Lieutenant 2nd Class
<option value="<?php echo $lt ?>">Lieutenant
<option value="<?php echo $ltcommander ?>">Lieutenant Commander
<option value="<?php echo $commander ?>">Commander
<option value="<?php echo $captain ?>">Captain
<option value="<?php echo $srcaptain ?>">Senior Captain
<option value="<?php echo $vadmiral ?>">Vice Admiral
<option value="<?php echo $admiral ?>">Admiral
<option value="<?php echo $cncxo ?>">CnC XO
<option value="<?php echo $cnc ?>">CnC
</select>
<input type="Submit" name="submit" value="Enter information">
</font>
</form>
<?php
}
?>
Thanks for any help, I've been messing about trying to sort it out for ages but I just can't seem to sort it!