I'm trying to create an all-in-one form that will allow me to insert,edit, and delete data based on url variables.
I'm running into a problem wherewhen I select a row to be edited I get two rows (in this case this is all of the rows in that particular table).
<?php
// includes
include("../includes/config.php");
include("../includes/functions.php");
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
?>
<html>
<head>
<basefont face="Verdana">
<link rel="stylesheet" href="../css/styles.css" type="text/css"></head>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<!-- standard page header begins -->
<table width="100%" border="0" cellspacing="0" cellpadding="0" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<tr>
<td width="25%"><img src="../images/<?php echo "$CompanyLogoName" ; ?>" width="200" height="45"></td>
<td width="49%" bgcolor="#000000"><img src="../images/<?php echo "$AdminBg" ;?>"></td>
<td width="26%" bgcolor="#000000" align="right" valign="bottom"><b><font color="<?php echo "$AdminDateColor" ;?>">
<?
//prints todays date
$today=date("F d, Y");
print"$today";
?> </font></b></td>
</tr>
</table>
<table width="100%" cellspacing="0" cellpadding="5" marginwidth="0" marginheight="0" leftmargin="0" topmargin="0">
<tr>
<td></td>
</tr>
<tr>
<td bgcolor="CC0000"><font size="-1" color="White"><b><?php echo "$CompanyName" ; ?>:
Administration</b></font></td>
</tr>
<tr>
<td align="left" valign="top">
</tr>
<p>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="15%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" valign>
<tr>
<td bgcolor="#333333"><div align="center"></div></td>
</tr>
<tr>
<td height="35" bgcolor="#333333"><div align="center" valign="middle"><font color="#FFFFFF"><strong>Site Content<br></strong></font></div></td>
</tr>
<tr><td height="1" bgcolor="#FFFFFF"></td></tr>
<tr>
<td height="400" bgcolor="#cc0000" valign="top"><br>
<?php
//generates and executes query listing FunctionName and FunctionDisplayName
$qryListFunctionName = mysql_query ("Select FunctionName,FunctionDisplayName from tblFunction");
while ($FunctionName_row = mysql_fetch_array($qryListFunctionName)){
echo "<p> <a class=\"FunctionName\" href=\"http://localhost/mnetsys/admin/list2.php?function=".$FunctionName_row["FunctionName"]."&action=display\">".$FunctionName_row["FunctionDisplayName"]."</a><br></p>";
}
?>
<br>
</td>
</tr>
</table></td>
<td width="74%" colspan="2" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" bgcolor="#CCCCCC">
<?php
//generates and executes query listing of Actions: Display, Edit, Insert
$qryListAction = mysql_query ("Select ActionName,ActionDisplayName FROM tblAction");
while ($Action_row = mysql_fetch_array($qryListAction)){
echo " ".$Action_row["ActionName"]." |";
}
?>
</td>
</tr>
<tr>
<td width="4%"> </td>
<td width="96%"><br><?php
//generates list of readable function names
$qryDisplayFunctionName = "SELECT FunctionDisplayName from tblFunction where FunctionName = '$function'";
$rsltDisplayFunctionName =mysql_query($qryDisplayFunctionName) or die ("Error in query: $qryDisplayFunctionName." . mysql_error());
if (mysql_num_rows($rsltDisplayFunctionName) >0)
{
while ($displayFunctionName_row = mysql_fetch_object($rsltDisplayFunctionName))
{
?><?php echo $displayFunctionName_row->FunctionDisplayName; ?><br><br>
<?php
// generate and execute query listing jobs
$qryListJob = "SELECT JobID, JobName, JobDesc FROM tblJob";
$rsltListJob = mysql_query($qryListJob) or die ("Error in query: $qryListJob. " . mysql_error());
// if records present
if (mysql_num_rows($rsltListJob) > 0)
{
// iterate through resultset
// print title with links to edit and delete scripts
while($job_row = mysql_fetch_object($rsltListJob))
{
if ($function == 'Career' AND $action == 'display')
{
echo ("
<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">
<tr>
<td align=\"left\"> <font size=\"-1\"><b>$job_row->JobName </b>
</font> <br>$job_row->JobDesc<br> <font size=\"-2\"><a href=\"edit.php?id=$job_row->JobID\">edit</a>
| <a href=\"delete.php?id=$job_row->JobID \">delete</a></font>
<p></td>
</tr>
");
}
}
}
?>
<?php
// generate and execute query listing clients
$qryListClient = "SELECT ClientID, ClientName FROM tblClient ORDER BY ClientName ASC";
$rsltListClient = mysql_query($qryListClient) or die ("Error in query: $qryListClient. " . mysql_error());
// if records present
if (mysql_num_rows($rsltListClient) > 0)
{
// iterate through resultset
// print title with links to edit and delete scripts
while($client_row = mysql_fetch_object($rsltListClient))
{
if ($function == 'Clients' AND $action == 'display')
{
echo ("
<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">
<tr>
<td align=\"left\"> <font size=\"-1\"><b>$client_row->ClientName </b>
</font> <br><font size=\"-2\"><a href=\"edit.php?id=$client_row->ClientID\">edit</a>
| <a href=\"delete.php?id=$client_row->ClientID\">delete</a></font>
<p></td>
</tr>
");
}
}
}
?>
<?php
// generate and execute query listing Solutions
$qryListSolution = "SELECT SolutionID, SolutionDisplayName FROM tblSolution ORDER BY SolutionDisplayName ASC";
$rsltListSolution = mysql_query($qryListSolution) or die ("Error in query: $qryListSolution. " . mysql_error());
// if records present
if (mysql_num_rows($rsltListSolution) > 0)
{
// iterate through resultset
// print title with links to edit and delete scripts
while($solution_row = mysql_fetch_object($rsltListSolution))
{
if ($function == 'Solutions' AND $action == 'display')
{
echo ("
<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">
<tr>
<td align=\"left\"> <font size=\"-1\"><b>$solution_row->SolutionDisplayName </b>
</font> <br><font size=\"-2\"><a href=\"edit.php?id=$solution_row->SolutionID\">edit</a>
| <a href=\"delete.php?id=$solution_row->SolutionID\">delete</a></font>
<p></td>
</tr>
");
}
}
}
?>
<?php
// generate and execute query listing partners
$qryListPartner = "SELECT PartnerID, PartnerDisplayName FROM tblPartner ORDER BY PartnerDisplayName ASC";
$rsltListPartner = mysql_query($qryListPartner) or die ("Error in query: $qryListPartner. " . mysql_error());
// if records present
if (mysql_num_rows($rsltListPartner) > 0)
{
// iterate through resultset
// print title with links to edit and delete scripts
while($partner_row = mysql_fetch_object($rsltListPartner))
{
if ($function == 'Partners' AND $action =='display')
{
echo ("
<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">
<tr>
<td align=\"left\"> <font size=\"-1\"><b>$partner_row->PartnerDisplayName </b>
</font> <br><font size=\"-2\"><a href=\"edit.php?id=$partner_row->PartnerID\">edit</a>
| <a href=\"delete.php?id=$partner_row->PartnerID\">delete</a></font>
<p></td>
</tr>
");
}
}
}
?>
<?php
// generate and execute query list Press Releases
$qryListPressRelease = "SELECT PressReleaseID, PressReleaseHeadline, PressReleaseDate, PressReleaseContent FROM tblPressRelease ORDER BY PressReleaseDate DESC";
$rsltListPressRelease = mysql_query($qryListPressRelease) or die ("Error in query: $qryListPressRelease. " . mysql_error());
// if records present
if (mysql_num_rows($rsltListPressRelease) > 0)
{
// iterate through resultset
// print title with links to edit and delete scripts
while($row = mysql_fetch_object($rsltListPressRelease))
{
if ($function == 'News' AND $action == 'display')
{
echo "
<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">
<tr>
<td align=\"left\"> <font size=\"-1\"><b>$row->PressReleaseHeadline</b>
[".formatDate($row->PressReleaseDate)."]</font> <br> <font size=\"-2\"><a href=\"?function=News&action=edit&id=$row->PressReleaseID\">edit</a>
| <a href=\"delete.php?id=$row->PressReleaseID\">delete</a></font>
<p></td>
</tr>
";
}
if ($function == 'News' AND $action == 'edit')
{
echo "
<form action=\"".$PHP_SELF."\" method=\"POST\">
<input type=\"hidden\" name=\"PressReleaseID\" value=\"".$row->PressReleaseID."\">".$row->PressReleaseID."
<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">
<tr>
<td align=\"left\"> <font size=\"-1\"><b>Headline:<input name=\"PressReleaseHeadline\" type=\"text\" value=\"".$row->PressReleaseHeadline."\"></b>
[".formatDate($row->PressReleaseDate)."]</font> <br> <font size=\"-2\">
<p></td>
<td align=\"left\"> <font size=\"-1\"><b>Content:<textarea cols=\"40\" rows=\"10\" name=\"PressReleaseContent\"> ".$row->PressReleaseContent." </textarea></b>
<p></td>
</tr>
</form>
";
}[/B]
elseif ($function == "")
{
echo ("No function selected");
}
}
}
}
}
// close connection
mysql_close($connection);
?>
<tr>
<td><font size="-2"><a href="news/add.php">add new</a></font></td>
</tr></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>