Hi
This is my first post on here so hello, and before we go any further I have next to no real knowledge of PHP.
I am in the process of building a website located at : http://www.ilt.bridgwater.ac.uk/~staua
The site is primarily written in html, but I have a couple of mysql table linked to it via php.
Everything is working fine except for one thing?.on the contacts link on the left hand side I want to be able to do the following:
Click on the link ---->open up my table (mysql) called ?contactslists.php?
This opens in the frame called main. This currently works fine?
Problem starts here.
I want to be able to amend a record, ideally I would like to be able to click on my amend records button and then give me a drop down box to select the record to amend.
I then want the select record to populate the fields on the form that is currently visible after the amend records button is selected.
I would then need a button to confirm and update my table.
Below is the code for my phpfiles
Upon clicking the contacts on the left frame the following file is activated:
<html>
<head>
<title>RTFC Contacts</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<?php
import_request_variables('p');
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 = "database";
$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 write_form()
{
global $PHP_SELF;
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="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 "";
?>
</td><td>
<?php
}
?>
</body>
</html>
When the Amend button is clicked on the above form the following phpfile is activated:
[code]
Contacts List <?php $user = "username"; $pass = "password"; $db = "database"; $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 "RTFC Officials Contact Details
"; print "$field | n"; print "
I hope this makes some sense, please help
Andy