right many thanks, but i have had a slight change of angle here, which i know makes it difficult for you to hit a moving target, but still....
i have now opted for radio buttons
i have the following code which sort of works to a point:
it is founsd at: http://www.ilt.bridgwater.ac.uk/~staua/contactslist.php
contacts list:
html>
<head>
<title>Contacts List</title>
<link rel="stylesheet" href="stylesheet.css" />
</head>
<body>
<?php
$user = "username";
$pass = "password";
$db = "dbname";
$link = mysql_connect("localhost",$user,$pass);
if (!$link) die("Couldn't connect to MySQL server");
mysql_select_db($db, $link) or die("Couldn't open $db: ".mysql_error());
$result = mysql_query("SELECT * FROM Contacts");
$num_rows = mysql_num_rows($result);
print "<h2>RTFC Officials Contact Details</h2>";
print "<form method='post' action='Contacts.php'>\n";
print "<table border=\"1\">\n";
while ($a_row = mysql_fetch_row($result))
{
print "<tr>\n";
if ($a_row[1] == "")
print "\t<td> </td>\n";
else
print "\t<td>$a_row[1]</td>\n";
if ($a_row[2] == "")
print "\t<td> </td>\n";
else
print "\t<td>$a_row[2]</td>\n";
if ($a_row[3] == "")
print "\t<td> </td>\n";
else
print "\t<td>$a_row[3]</td>\n";
if ($a_row[4] == "")
print "\t<td> </td>\n";
else
print "\t<td>$a_row[4]</td>\n";
print "\t<td>$field</td><td><input name='opt' type='radio' value=$a_row[0]></td>\n";
print "</tr>\n";
}
print "</table>\n";
print "<p><input type=\"submit\" value=\"Add A New Record\"></p>\n";
print "</form>\n"; mysql_close($link);?>
</body>
</html>
how this works is that if no radio button is clicked it should act as a new entry is to be added, however if a radio button is used then it will take on the Amend process to alter current data.
when the radio button is activated and the button clicked the following code is used:
Contacts.php
<html>
<head>
<title>RTFC Newsletter</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<?php
import_request_variables('p');
if (isset($opt))
{
if (isset($name2) && isset($email2) && isset($position2) && isset($tel2))
{
// check user input here
$dberror = "";
$ret = update_database($name2,$position2,$email2,$tel2,$dberror);
if (!$ret)
print "Error: $dberror<br />";
else
print "<h2>Thank you very much, $name has been added </h2>";
}
else
{
$user = "username";
$pass = "password";
$db = "dbname";
$link = mysql_connect("localhost",$user,$pass);
if (!$link) die("Couldn't connect to MySQL server");
mysql_select_db($db, $link) or die("Couldn't open $db: ".mysql_error());
$result = mysql_query("SELECT * FROM Contacts WHERE ID='".$pos."'");
$num_rows = mysql_num_rows($result);
$a_row = mysql_fetch_row($result);
print "numrows = '$num_rows'";
write_form2($a_row[1], $a_row[2], $a_row[3], $a_row[4]);
}
}
else
{
if (isset($name) && isset($email) && isset($position) && isset($tel))
{
// check user input here
$dberror = "";
$ret = add_to_database($name,$position,$email,$tel,$dberror);
if (!$ret)
print "Error: $dberror<br />";
else
print "<h2>Thank you very much, $name has been added </h2>";
}
else
write_form();
}
function add_to_database($name, $position, $email, $tel, &$dberror)
{
$user = "username";
$pass = "password";
$db = "dbname";
$link = mysql_connect("localhost",$user,$pass);
if (!$link)
{
$dberror = "Couldn't connect to MySQL server";
return false;
}
if (!mysql_select_db($db, $link))
{
$dberror = mysql_error();
return false;
}
$query="INSERT INTO Contacts (Name, Position, Email, Tel)
VALUES('$name', '$position', '$email', '$tel' )";
if (!mysql_query($query, $link))
{
$dberror = mysql_error();
return false;
}
return true;
// mysql_close($link);
}
function update_database($name2, $position2, $email2, $tel2, &$dberror)
{
$user = "username";
$pass = "password";
$db = "dbname";
$link = mysql_connect("localhost",$user,$pass);
if (!$link)
{
$dberror = "Couldn't connect to MySQL server";
return false;
}
if (!mysql_select_db($db, $link))
{
$dberror = mysql_error();
return false;
}
$query="UPDATE Contacts SET Name='$name2', Position='$position2', Email='$email2', Tel='$tel2'
WHERE ID='$pos'";
if (!mysql_query($query, $link))
{
$dberror = mysql_error();
return false;
}
return true;
// mysql_close($link);
}
function write_form()
{
global $PHP_SELF;
print "<form action=\"$PHP_SELF\"method=\"POST\">\n";
print "<p><h2>Please Add Details As Required</h2></p>";
print "<form action=\"$PHP_SELF\" method=\"POST\">\n";
print " <p> Officials Name</p>\n";
print "<input type=\"text\" name=\"name\">";
print " <p> Officials Position</p>\n";
print "<input type=\"text\" name=\"position\">";
print " <p> Your e-mail address</p>\n";
print "<input type=\"text\" name=\"email\">";
print " <p> Officials Tel</p>\n";
print "<input type=\"text\" name=\"tel\">";
print "<p><input type=\"submit\" value=\"Register\"></p>\n</form>\n";
print "";
}
function write_form2($name2, $position2, $email2, $tel2)
{
global $PHP_SELF;
print "name2 = '$name2'";
print "<form action=\"$PHP_SELF\"method=\"POST\">\n";
print "<p><h2>Please Ammend Details As Required</h2></p>";
print "<form action=\"$PHP_SELF\" method=\"POST\">\n";
print " <p> Officials Name</p>\n";
print "<input type=\"text\" name=\"name2\" value=$name2>";
print " <p> Officials Position</p>\n";
print "<input type=\"text\" name=\"position2\" value=$position2>";
print " <p> Your e-mail address</p>\n";
print "<input type=\"text\" name=\"email2\" value=$email2>";
print " <p> Officials Tel</p>\n";
print "<input type=\"text\" name=\"tel2\" value=$tel2>";
print "<input type=\"hidden\" name=\"pos\" value=$pos>";
print "<p><input type=\"submit\" value=\"Register\"></p>\n</form>\n";
print "";
}
?>
<? print "opt = '$opt'"; ?>
</body>
</html>
the trouble i am having is that i want the data that is attached to the relevant radio button to be copied across to the fields for ammending, but they are not being transferred.
i am really desperate for some help here please, i am even prepared to give you access to my site if that help.