shaunah
08-12-2002, 08:18 PM
I seem to be doing something wrong. I'm using PHP 4.22 and am wanting to edit the content of a single record. However, I can't ever get the record to update. Can someone help me find out where I'm going wrong??? Thanks!!
<?
session_start();
$id = $_GET["id"];
$server = "localhost";
$user = "xxx";
$pass = "xxx";
$database = "xxx";
if (isset($Submit)):
{
$id = $_GET["id"];
$sql = "update employees
set first = '$first',
last = '$last',
department = '$department',
title = '$title',
extension = '$extension',
email = '$email',
bday = '$bday',
anniversary = '$anniversary',
bio = '$bio',
homephone = '$homephone',
cellphone = '$cellphone',
username = '$username',
password = '$password',
WHERE id = $id";
$result = mysql_query($sql, $connection);
}
endif;
$connection = mysql_connect($server, $user, $pass);
mysql_select_db($database, $connection);
$sql = "SELECT * FROM employees WHERE id = '$id'";
$result = mysql_query($sql, $connection);
while ($row = mysql_fetch_array($result)) {
echo ("<form name=\"form1\" method=\"post\" action=\"index.php?id=");
echo ("$id");
echo ("\">");
echo ("<p><img src=\"");
echo ("photos/");
echo ("$row[photo]");
echo (".jpg\" ");
echo ("width=\"100\" height=\"150\" align=\"left\"><b>");
echo ("First: <input type=\"text\" value=\"");
echo ("$row[first]");
echo ("\" name=\"first\">");
echo ("<br>");
echo ("Last: <input type=\"text\" value=\"");
echo ("$row[last]");
echo ("\" name=\"last\">");
echo ("<br>");
echo ("Department: <input type=\"text\" value=\"");
echo ("$row[department]");
echo ("\" name=\"department\">");
echo ("<br>");
echo ("Title: <input type=\"text\" value=\"");
echo ("$row[position]");
echo ("\" name=\"title\">");
echo ("<br>");
echo ("Work Phone: <input type=\"text\" value=\"");
echo ("$row[extension]");
echo ("\" name=\"extension\">");
echo ("<br>");
echo ("Email: <input type=\"text\" value=\"");
echo ("$row[email]");
echo ("\" name=\"email\">");
echo ("<br>");
echo ("Birthday: <input type=\"text\" value=\"");
echo ("$row[bday]");
echo ("\" name=\"bday\">");
echo ("<br>");
echo ("Anniversary: <input type=\"text\" value=\"");
echo ("$row[anniversary]");
echo ("\" name=\"anniversary\">");
echo ("<br>");
echo ("<br>");
echo ("<br>");
echo ("Biography: <br><textarea name=\"bio\" rows=\"5\" cols=\"30\">");
echo ("$row[bio]");
echo ("</textarea>");
echo ("<br>");
echo ("Home Phone: <input type=\"text\" value=\"");
echo ("$row[homephone]");
echo ("\" name=\"homephone\">");
echo ("<br>");
echo ("Cell Phone: <input type=\"text\" value=\"");
echo ("$row[cellphone]");
echo ("\" name=\"cellphone\">");
echo ("<br>");
echo ("Pager: <input type=\"text\" value=\"");
echo ("$row[pager]");
echo ("\" name=\"pager\">");
echo ("<br>");
echo ("User Name (for updating this information): <input type=\"text\" value=\"");
echo ("$row[username]");
echo ("\" name=\"username\">");
echo ("<br>");
echo ("Password (for updating this information): <input type=\"text\" value=\"");
echo ("$row[password]");
echo ("\" name=\"password\">");
echo ("<br><br><input type=\"submit\" name=\"Submit\" value=\"Submit\"></form>");
}
?>
<?
session_start();
$id = $_GET["id"];
$server = "localhost";
$user = "xxx";
$pass = "xxx";
$database = "xxx";
if (isset($Submit)):
{
$id = $_GET["id"];
$sql = "update employees
set first = '$first',
last = '$last',
department = '$department',
title = '$title',
extension = '$extension',
email = '$email',
bday = '$bday',
anniversary = '$anniversary',
bio = '$bio',
homephone = '$homephone',
cellphone = '$cellphone',
username = '$username',
password = '$password',
WHERE id = $id";
$result = mysql_query($sql, $connection);
}
endif;
$connection = mysql_connect($server, $user, $pass);
mysql_select_db($database, $connection);
$sql = "SELECT * FROM employees WHERE id = '$id'";
$result = mysql_query($sql, $connection);
while ($row = mysql_fetch_array($result)) {
echo ("<form name=\"form1\" method=\"post\" action=\"index.php?id=");
echo ("$id");
echo ("\">");
echo ("<p><img src=\"");
echo ("photos/");
echo ("$row[photo]");
echo (".jpg\" ");
echo ("width=\"100\" height=\"150\" align=\"left\"><b>");
echo ("First: <input type=\"text\" value=\"");
echo ("$row[first]");
echo ("\" name=\"first\">");
echo ("<br>");
echo ("Last: <input type=\"text\" value=\"");
echo ("$row[last]");
echo ("\" name=\"last\">");
echo ("<br>");
echo ("Department: <input type=\"text\" value=\"");
echo ("$row[department]");
echo ("\" name=\"department\">");
echo ("<br>");
echo ("Title: <input type=\"text\" value=\"");
echo ("$row[position]");
echo ("\" name=\"title\">");
echo ("<br>");
echo ("Work Phone: <input type=\"text\" value=\"");
echo ("$row[extension]");
echo ("\" name=\"extension\">");
echo ("<br>");
echo ("Email: <input type=\"text\" value=\"");
echo ("$row[email]");
echo ("\" name=\"email\">");
echo ("<br>");
echo ("Birthday: <input type=\"text\" value=\"");
echo ("$row[bday]");
echo ("\" name=\"bday\">");
echo ("<br>");
echo ("Anniversary: <input type=\"text\" value=\"");
echo ("$row[anniversary]");
echo ("\" name=\"anniversary\">");
echo ("<br>");
echo ("<br>");
echo ("<br>");
echo ("Biography: <br><textarea name=\"bio\" rows=\"5\" cols=\"30\">");
echo ("$row[bio]");
echo ("</textarea>");
echo ("<br>");
echo ("Home Phone: <input type=\"text\" value=\"");
echo ("$row[homephone]");
echo ("\" name=\"homephone\">");
echo ("<br>");
echo ("Cell Phone: <input type=\"text\" value=\"");
echo ("$row[cellphone]");
echo ("\" name=\"cellphone\">");
echo ("<br>");
echo ("Pager: <input type=\"text\" value=\"");
echo ("$row[pager]");
echo ("\" name=\"pager\">");
echo ("<br>");
echo ("User Name (for updating this information): <input type=\"text\" value=\"");
echo ("$row[username]");
echo ("\" name=\"username\">");
echo ("<br>");
echo ("Password (for updating this information): <input type=\"text\" value=\"");
echo ("$row[password]");
echo ("\" name=\"password\">");
echo ("<br><br><input type=\"submit\" name=\"Submit\" value=\"Submit\"></form>");
}
?>