Hi again. I've been tackling another tutorial which isn't working fully, basically it lists records in a table and an insert link sends the data to a text field which can then be modified. The data is displayed fine but when selected the form does not recieve the information. Its a simple table called test4 with unique key id and field Tom. Here is the code;
<?php
$dbhost='localhost';
$dbusername='root';
$dbname = 'test';
mysql_connect ($dbhost, $dbusername);
mysql_select_db($dbname) or die('Cannot select database');
if(!isset($cmd)) {
$result = mysql_query("SELECT * FROM test4");
while($row=mysql_fetch_array($result))
{
$Tom=$row["Tom"];
$id=$row["id"];
echo "<strong> tom</strong>: {$row['Tom']}</p>";
echo "<strong> id</strong>: {$row['id']}</p>";
echo "<a href='untitled.php?cmd=edit&id=$id'>$Tom - Edit</a>";
echo "<br>";
}
}
?>
<?php
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = (int)$_GET['id'];
$sql = mysql_query ("SELECT * FROM test4 WHERE id='$id'");
$result = mysql_fetch_array($sql);
$myrow = @mysql_fetch_array($result);
?>
<form action="untitled.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
Value in row Tom:<INPUT TYPE="TEXT" NAME="Tom" VALUE="<?php echo $myrow["Tom"] ?>" SIZE=20><br>
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</form>
<?php } ?>
<?php
if ($_POST["submit"])
{
$Tom = $_POST["Tom"];
$sql = "UPDATE test4 SET Tom='$Tom' WHERE id='$id'";
$result = mysql_query($sql);
echo "Success!";
}
}
?>
Any help will be very much appreciated.
(Don't worry this is the last tutorila I'm doing, finished them for now!)