Hello -
I’ve been working on creating a customer email list for a company. I’ve got a form set up so that when the user submits their info, it is saved to a database. Next I’ve created a page where authorized users can view the list of customers and their emails. Now I want to add the option for them to delete individual fields from the database… that’s where I’m all hung up. Any help would be greatly appreciated.
Below is the code:
[php]//access Address Database and Table
$DBName = “database”;
$DBConnect = @mysql_connect(“localhost”,“database”,“password”);
if ($DBConnect === FALSE)//connection error
echo "
Connection Error: " . mysql_error() . “
\n”;else {
	
		if (@mysql_select_db($DBName, $DbConnect) === FALSE) { //error - no db selected
			echo "<p>Could not select the \"$DBName\" database: " . mysql_error($DBConnect) . "</p>\n";
			mysql_close($DBConnect);
			$DBConnect = FALSE;
			}
	
	
	}
          
          if ($DBConnect !== FALSE) { //all connections are good
              @mysql_select_db($DBName);//selects database
              $SQLstring = "SELECT * FROM Addresses ORDER BY lName"; //run query to select Client info and order by their last name
              $QueryResult = @mysql_query($SQLstring, $DBConnect); //check query result
     
              if($QueryResult === FALSE)
                  echo"<p>There are no addresses in the database database. Thank you!</p>" 
                  . "<p>Error Code " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>";
                  
              else{ //query result ran - now display result in a table
         			  echo "<table width='620px' border='none'>\n";
				  echo "<tr><th>Last Name</th><th>First Name</th><th>Address</th><th>Home Phone</th><th>Email</th></tr>\n";
				  while (($Row = mysql_fetch_row($QueryResult)) !== FALSE) {
				   	
					  echo "<tr><td>{$Row[2]}</td>";
					  echo "<td>{$Row[1]}</td>";
					  echo "<td>{$Row[8]} {$Row[5]}, {$Row[6]} {$Row[7]} </td>";
					  echo"<td>{$Row[3]}</td>";
					  echo "<td>{$Row[4]}</td>\n";
					  echo"<td>" . "<a href='displayAddress.php?" . "action=Delete%20Entry&" . "name=$Row[4]'>" . "Delete</a></td></tr>\n";  //possible way to delete records???
					  if(isset($_GET['action'])) { //run action to run query??
						$SQLDelete = "DELETE FROM 'Addresses' WHERE email = 'name'";
						$QueryDelete = @mysql_query($SQLDelete, $DBConnect);						
	
							}
		
					  }
					  echo "</table>\n";
			  }
              mysql_close($DBConnect);
              }
			  [/php]